Skip to content

Commit

Permalink
Add Paris RPC queries (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
k-karuna authored May 15, 2024
1 parent c870e9f commit 72bee4e
Show file tree
Hide file tree
Showing 17 changed files with 204 additions and 45 deletions.
101 changes: 87 additions & 14 deletions Netezos.Tests/Rpc/TestContextQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ public async Task TestContextContractEntrypoints()
Assert.True(res is DJsonObject);
}

[Fact]
public async Task TestContextContractEstimatedOwnPendingSlashedAmount()
{
var query = Rpc.Blocks.Head.Context.Contracts[TestContract].EstimatedOwnPendingSlashedAmount;
Assert.Equal($"chains/main/blocks/head/context/contracts/{TestContract}/estimated_own_pending_slashed_amount/",
query.ToString());

var res = await query.GetAsync();
Assert.True(res is DJsonValue);
}

[Fact]
public async Task TestContextContractEntrypoint()
{
Expand Down Expand Up @@ -282,7 +293,7 @@ public async Task TestContextContractUnstakeRequests()
Assert.Equal($"chains/main/blocks/head/context/contracts/{TestDelegate}/unstake_requests/", query.ToString());

var res = await query.GetAsync();
Assert.True(res is DJsonObject);
Assert.True(res is DJsonObject || res == null);
}

[Fact]
Expand All @@ -305,6 +316,36 @@ public async Task TestContextContractUnstakedFrozenBalance()
Assert.True(res is DJsonValue);
}

[Fact]
public async Task TestContextDalCommitmentsHistory()
{
var query = Rpc.Blocks.Head.Context.Dal.CommitmentsHistory;
Assert.Equal("chains/main/blocks/head/context/dal/commitments_history/", query.ToString());

var res = await query.GetAsync();
Assert.True(res is DJsonObject);
}

[Fact]
public async Task TestContextDalPublishedSlotHeaders()
{
var query = Rpc.Blocks.Head.Context.Dal.PublishedSlotHeaders;
Assert.Equal("chains/main/blocks/head/context/dal/published_slot_headers/", query.ToString());

var res = await query.GetAsync();
Assert.True(res is DJsonArray);
}

[Fact]
public async Task TestContextDalShards()
{
var query = Rpc.Blocks.Head.Context.Dal.Shards;
Assert.Equal("chains/main/blocks/head/context/dal/shards/", query.ToString());

var res = await query.GetAsync();
Assert.True(res is DJsonArray);
}

[Fact]
public async Task TestContextDelegates()
{
Expand All @@ -314,8 +355,8 @@ public async Task TestContextDelegates()
var res = await query.GetAsync();
Assert.True(res is DJsonArray);

var deleegateActiveRes = await query.GetAsync(DelegateStatus.Active);
Assert.True(deleegateActiveRes is DJsonArray);
var delegateActiveRes = await query.GetAsync(DelegateStatus.Active);
Assert.True(delegateActiveRes is DJsonArray);

var delegateInactiveRes = await query.GetAsync(DelegateStatus.Inactive);
Assert.True(delegateInactiveRes is DJsonArray);
Expand Down Expand Up @@ -410,7 +451,49 @@ public async Task TestContextDelegateDelegatedContracts()
var res = await query.GetAsync();
Assert.True(res is DJsonArray);
}


[Fact]
public async Task TestContextDelegateDenunciations()
{
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].Denunciations;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/denunciations/", query.ToString());

var res = await query.GetAsync();
Assert.True(res is DJsonArray);
}

[Fact]
public async Task TestContextDelegateEstimatedSharedPendingSlashedAmount()
{
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].EstimatedSharedPendingSlashedAmount;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/estimated_shared_pending_slashed_amount/",
query.ToString());

var res = await query.GetAsync();
Assert.True(res is DJsonValue);
}

[Fact]
public async Task TestContextDelegateIsForbidden()
{
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].IsForbidden;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/is_forbidden/", query.ToString());

var res = await query.GetAsync();
Assert.True(res is DJsonValue);
}

[Fact]
public async Task TestContextDelegateMinDelegatedInCurrentCycle()
{
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].MinDelegatedInCurrentCycle;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/min_delegated_in_current_cycle/",
query.ToString());

var res = await query.GetAsync();
Assert.True(res is DJsonObject);
}

[Fact]
public async Task TestContextDelegateFrozenDeposits()
{
Expand Down Expand Up @@ -584,16 +667,6 @@ public async Task TestContextSmartRollupGenesisInfo()
Assert.True(res is DJsonObject);
}

[Fact]
public async Task TestContextSmartRollupInitialPvmStateHash()
{
var query = Rpc.Blocks.Head.Context.SmartRollups[TestSmartRollup].InitialPvmStateHash;
Assert.Equal($"chains/main/blocks/head/context/smart_rollups/smart_rollup/{TestSmartRollup}/initial_pvm_state_hash/", query.ToString());

var res = await query.GetAsync();
Assert.True(res is DJsonValue);
}

[Fact]
public async Task TestContextSmartRollupKind()
{
Expand Down
10 changes: 0 additions & 10 deletions Netezos.Tests/Rpc/TestHelpersQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ public async Task TestHelpersCurrentLevel()
Assert.True(res is DJsonObject);
}

[Fact]
public async Task TestHelpersEndorsingRights()
{
var query = Rpc.Blocks.Head.Helpers.EndorsingRights;
Assert.Equal($"chains/main/blocks/head/helpers/endorsing_rights", query.ToString());

var res = await query.GetAsync();
Assert.True(res is DJsonArray);
}

[Fact]
public void TestHelpersForgeBlockHeader()
{
Expand Down
12 changes: 1 addition & 11 deletions Netezos.Tests/Rpc/TestRawContextQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,6 @@ public async Task TestRawContextContractDelegated()
Assert.True(res is DJsonArray);
}

[Fact]
public async Task TestRawContextContractFrozenDeposits()
{
var query = Rpc.Blocks.Head.Context.Raw.Contracts[TestDelegate].FrozenDeposits;
Assert.Equal($"chains/main/blocks/head/context/raw/json/contracts/index/{TestDelegate}/frozen_deposits/", query.ToString());

var res = await query.GetAsync();
Assert.True(res is DJsonObject);
}

[Fact]
public async Task TestRawContextContractManager()
{
Expand Down Expand Up @@ -195,7 +185,7 @@ public async Task TestRawContextContractStorage()
Assert.Equal($"chains/main/blocks/head/context/raw/json/contracts/index/{TestContract}/storage/", query.ToString());

var res = await query.GetAsync();
Assert.True(res is DJsonObject);
Assert.True(res is DJsonArray);
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions Netezos.Tests/Rpc/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"node": "https://rpc.tzkt.io/mainnet/",
"testContract": "KT1WPEis2WhAc2FciM2tZVn8qe6pCBe9HkDp",
"testEntrypoint": "Action",
"testContract": "KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5",
"testEntrypoint": "default",
"testDelegate": "tz3bvNMQ95vfAYtG8193ymshqjSvmxiCUuR5",
"testInactive": "tz1bR8MFMyWSa428KRQcdShZFu9C4gEA4iFd",
"testSmartRollup": "sr1M8qwvJuzmB5fgu4JFS2gtUvC3CBGs7TQx",
Expand Down
4 changes: 2 additions & 2 deletions Netezos.Tests/Rpc/settings_ithaca.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"node": "https://rpc.tzkt.io/ithacanet/",
"testContract": "KT1GHz4zehbss9hxsYsTbppRgozXxaLJLM2R",
"testEntrypoint": "do",
"testContract": "KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5",
"testEntrypoint": "default",
"testDelegate": "tz1aWXP237BLwNHJcCD4b3DutCevhqq2T1Z9",
"testInactive": "tz1Wn7JnLVf7PpTbaLQNzmNaF9z9UudWHGBR",
"keyHash": "expru2dKqDfZG8hu4wNGkiyunvq2hdSKuVYtcKta7BWP6Q18oNxKjS",
Expand Down
2 changes: 1 addition & 1 deletion Netezos.Tests/Rpc/settings_oxford.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"node": "https://rpc.tzkt.io/oxfordnet/",
"testContract": "KT1XtHJBXF3aAwggHrZh1fUbzaHc5MmB6QDs",
"testContract": "KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5",
"testEntrypoint": "default",
"testDelegate": "tz1foXHgRzdYdaLgX6XhpZGxbBv42LZ6ubvE",
"testInactive": "tz2Wjf3XgkgxWF4nMJM2cKqbgTQ8as7agMM2",
Expand Down
10 changes: 10 additions & 0 deletions Netezos.Tests/Rpc/settings_parisnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"node": "https://rpc.tzkt.io/parisnet/",
"testContract": "KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5",
"testEntrypoint": "default",
"testDelegate": "tz1gBnaS1n7LKqpaRnyBX5MSmamadXXfzNpt",
"testInactive": "tz2Vs8rfURNu4fQpQwhWc1sWgTqzZ9TW8mc8",
"testSmartRollup": "sr1QurxjyVCePny7i5kHWq1w8W95LsFLxUUk",
"keyHash": "exprvBfbrdZVCjkmcsJRpioTnZdos3RLMZUDTK2AyFURY423xuWX4N",
"bigMapId": "2"
}
8 changes: 7 additions & 1 deletion Netezos/Rpc/Queries/ContextQuery.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Netezos.Rpc.Queries.Post;
using Netezos.Rpc.Queries.Dal;
using Netezos.Rpc.Queries.Post;

namespace Netezos.Rpc.Queries
{
Expand Down Expand Up @@ -27,6 +28,11 @@ public class ContextQuery : RpcQuery
/// </summary>
public ContractsQuery Contracts => new(this, "contracts/");

/// <summary>
/// Gets the query to Data-Availability Layer
/// </summary>
public DalQuery Dal => new(this, "dal/");

/// <summary>
/// Gets the query to all registered delegates
/// </summary>
Expand Down
7 changes: 6 additions & 1 deletion Netezos/Rpc/Queries/ContractQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Netezos.Rpc.Queries
public class ContractQuery : RpcObject
{
/// <summary>
/// Gets the query to the the complete list of tickets owned by the given contract by scanning the contract's storage.
/// Gets the query to the complete list of tickets owned by the given contract by scanning the contract's storage.
/// </summary>
public RpcObject AllTicketBalances => new(this, "all_ticket_balances/");

Expand Down Expand Up @@ -49,6 +49,11 @@ public class ContractQuery : RpcObject
/// </summary>
public EntrypointsQuery Entrypoints => new(this, "entrypoints/");

/// <summary>
/// Gets the query to the estimated own pending slashed amount (in mutez) of a contract.
/// </summary>
public RpcObject EstimatedOwnPendingSlashedAmount => new(this, "estimated_own_pending_slashed_amount/");

/// <summary>
/// Gets the query to the frozen bonds of a contract.
/// </summary>
Expand Down
23 changes: 23 additions & 0 deletions Netezos/Rpc/Queries/Dal/DalQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Netezos.Rpc.Queries.Dal
{
public class DalQuery : RpcQuery
{
/// <summary>
/// Gets the query to the (currently last) DAL skip list cell if DAL is enabled, or [None] otherwise.
/// </summary>
public RpcObject CommitmentsHistory => new(this, "commitments_history/");

/// <summary>
/// Gets the query to the published slots headers for the given level.
/// </summary>
public PublishedSlotHeadersQuery PublishedSlotHeaders => new(this, "published_slot_headers/");

/// <summary>
/// Gets the query to the shards assignment for a given level (the default is the current level) and given
/// delegates (the default is all delegates)
/// </summary>
public ShardsQuery Shards => new(this, "shards/");

internal DalQuery(RpcQuery baseQuery, string append) : base(baseQuery, append) { }
}
}
19 changes: 19 additions & 0 deletions Netezos/Rpc/Queries/Dal/PublishedSlotHeadersQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Netezos.Rpc.Queries.Dal;

public class PublishedSlotHeadersQuery : RpcObject
{
/// <summary>
/// Get the published slots headers for the current level.
/// </summary>
/// <returns></returns>
public new Task<dynamic> GetAsync() => Client.GetJson(Query);

/// <summary>
/// Get the published slots headers for the given level
/// </summary>
/// <param name="level">Level of the block</param>
/// <returns></returns>
public Task<dynamic> GetAsync(int level) => Client.GetJson($"{Query}?level={level}");

internal PublishedSlotHeadersQuery(RpcQuery baseQuery, string append) : base(baseQuery, append) { }
}
19 changes: 19 additions & 0 deletions Netezos/Rpc/Queries/Dal/ShardsQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Netezos.Rpc.Queries.Dal;

public class ShardsQuery : RpcObject
{
/// <summary>
/// Get the shards assignment for a current level and all delegates.
/// </summary>
public new Task<dynamic> GetAsync() => Client.GetJson(Query);

/// <summary>
/// Get the shards assignment for a given level and given delegates.
/// </summary>
/// <param name="level">Level of the block</param>
/// <param name="delegates">A Secp256k1 or an Ed25519 public key hash (Base58Check-encoded)</param>
public new Task<dynamic> GetAsync(int level, string delegates)
=> Client.GetJson($"{Query}?level={level}&delegates={delegates}");

internal ShardsQuery(RpcQuery baseQuery, string append) : base(baseQuery, append) { }
}
25 changes: 23 additions & 2 deletions Netezos/Rpc/Queries/DelegateQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class DelegateQuery : RpcObject
public RpcObject ConsensusKey => new(this, "consensus_key/");

/// <summary>
/// The baking power of a delegate, as computed from its current stake. This value is not used for computing baking rights
/// but only reflects the baking power that the delegate would have if a snapshot was taken at the current block.
/// The baking power of a delegate, as computed from its current stake. This value is not used for computing baking
/// rights but only reflects the baking power that the delegate would have if the cycle ended at the current block.
/// </summary>
public RpcObject CurrentBakingPower => new(this, "current_baking_power/");

Expand Down Expand Up @@ -52,6 +52,16 @@ public class DelegateQuery : RpcObject
/// </summary>
public RpcObject DelegatedContracts => new(this, "delegated_contracts/");

/// <summary>
/// Gets the query to the pending denunciations for the given delegate.
/// </summary>
public RpcObject Denunciations => new(this, "denunciations/");

/// <summary>
/// Gets the query to the estimated shared pending slashed amount (in mutez) of a given delegate.
/// </summary>
public RpcObject EstimatedSharedPendingSlashedAmount => new(this, "estimated_shared_pending_slashed_amount/");

/// <summary>
/// Gets the query to the total frozen balances of a given delegate, this includes the frozen deposits, rewards and fees
/// </summary>
Expand Down Expand Up @@ -85,6 +95,17 @@ public class DelegateQuery : RpcObject
/// </summary>
public RpcObject GracePeriod => new(this, "grace_period/");

/// <summary>
/// Gets the query that returns true if the delegate is forbidden to participate in consensus.
/// </summary>
public RpcObject IsForbidden => new(this, "is_forbidden/");

/// <summary>
/// Gets the query to the minimum of delegated tez (in mutez) over the current cycle and the block level where
/// this value was last updated.
/// </summary>
public RpcObject MinDelegatedInCurrentCycle => new(this, "min_delegated_in_current_cycle/");

/// <summary>
/// Returns cycle and level participation information. In particular this indicates, in the field 'expected_cycle_activity',
/// the number of slots the delegate is expected to have in the cycle based on its active stake. The field 'minimal_cycle_activity' indicates the minimal endorsing slots in the cycle required to get endorsing rewards.
Expand Down
1 change: 1 addition & 0 deletions Netezos/Rpc/Queries/HelpersQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class HelpersQuery : RpcQuery
/// <summary>
/// Gets the query to the endorsing rights
/// </summary>
[Obsolete("This RPC query is deprecated. Use it on early protocols only.")]
public EndorsingRightsQuery EndorsingRights => new(this, "endorsing_rights");

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Netezos/Rpc/Queries/IssuanceQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class IssuanceQuery : RpcQuery
public RpcObject CurrentYearlyRateExact => new(this, "current_yearly_rate_exact/");

/// <summary>
/// Returns the expected issued tez for the provided block and the next five cycles.
/// Returns the expected issued tez for the provided block and the next 'consensus_rights_delay' cycles.
/// </summary>
public RpcObject ExpectedIssuance => new(this, "expected_issuance/");

Expand Down
1 change: 1 addition & 0 deletions Netezos/Rpc/Queries/RawContractQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class RawContractQuery : DeepRpcObject
/// <summary>
/// Gets the query to the frozen deposits
/// </summary>
[Obsolete("This RPC query was removed. Use it on early protocols only.")]
public RpcObject FrozenDeposits => new(this, "frozen_deposits/");

/// <summary>
Expand Down
Loading

0 comments on commit 72bee4e

Please sign in to comment.