Skip to content

Commit

Permalink
Update RPC spec for Octez v21.2 (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
k-karuna authored Jan 18, 2025
1 parent 75fe417 commit 439da5a
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 60 deletions.
146 changes: 108 additions & 38 deletions Netezos.Tests/Rpc/TestContextQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,26 @@ public async Task TestContextContractStakedBalance()
Assert.True(res is DJsonValue);
}

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

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

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

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

[Fact]
public async Task TestContextContractStorage()
{
Expand Down Expand Up @@ -383,73 +403,73 @@ public async Task TestContextDelegateActiveStakingParameters()
}

[Fact]
public async Task TestContextDelegateConsensusKey()
public async Task TestContextDelegateBakingPower()
{
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].ConsensusKey;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/consensus_key/", query.ToString());
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].BakingPower;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/baking_power/", query.ToString());

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

[Fact]
public async Task TestContextDelegateCurrentBakingPower()
public async Task TestContextDelegateDelegators()
{
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].CurrentBakingPower;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/current_baking_power/", query.ToString());
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].Delegators;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/delegators/", query.ToString());

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

[Fact]
public async Task TestContextDelegateCurrentFrozenDeposits()
public async Task TestContextDelegateExternalDelegated()
{
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].CurrentFrozenDeposits;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/current_frozen_deposits/", query.ToString());
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].ExternalDelegated;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/external_delegated/", query.ToString());

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

[Fact]
public async Task TestContextDelegateCurrentVotingPower()
public async Task TestContextDelegateExternalStaked()
{
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].CurrentVotingPower;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/current_voting_power/", query.ToString());
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].ExternalStaked;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/external_staked/", query.ToString());

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

[Fact]
public async Task TestContextDelegateDeactivated()
public async Task TestContextDelegateConsensusKey()
{
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].Deactivated;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/deactivated/", query.ToString());
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].ConsensusKey;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/consensus_key/", query.ToString());

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

[Fact]
public async Task TestContextDelegateDelegatedBalance()
public async Task TestContextDelegateCurrentVotingPower()
{
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].DelegatedBalance;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/delegated_balance/", query.ToString());
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].CurrentVotingPower;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/current_voting_power/", query.ToString());

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

[Fact]
public async Task TestContextDelegateDelegatedContracts()
public async Task TestContextDelegateDeactivated()
{
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].DelegatedContracts;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/delegated_contracts/", query.ToString());
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].Deactivated;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/deactivated/", query.ToString());

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

[Fact]
Expand All @@ -473,6 +493,16 @@ public async Task TestContextDelegateEstimatedSharedPendingSlashedAmount()
Assert.True(res is DJsonValue);
}

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

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

[Fact]
public async Task TestContextDelegateIsForbidden()
{
Expand All @@ -495,30 +525,30 @@ public async Task TestContextDelegateMinDelegatedInCurrentCycle()
}

[Fact]
public async Task TestContextDelegateFrozenDeposits()
public async Task TestContextDelegateOwnDelegated()
{
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].FrozenDeposits;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/frozen_deposits/", query.ToString());
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].OwnDelegated;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/own_delegated/", query.ToString());

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

[Fact]
public async Task TestContextDelegateFullBalance()
public async Task TestContextDelegateOwnFullBalance()
{
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].FullBalance;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/full_balance/", query.ToString());
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].OwnFullBalance;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/own_full_balance/", query.ToString());

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

[Fact]
public async Task TestContextDelegateGracePeriod()
public async Task TestContextDelegateOwnStaked()
{
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].GracePeriod;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/grace_period/", query.ToString());
var query = Rpc.Blocks.Head.Context.Delegates[TestDelegate].OwnStaked;
Assert.Equal($"chains/main/blocks/head/context/delegates/{TestDelegate}/own_staked/", query.ToString());

var res = await query.GetAsync();
Assert.True(res is DJsonValue);
Expand Down Expand Up @@ -555,10 +585,30 @@ public async Task TestContextDelegateStakingBalance()
}

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

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

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

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

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

var res = await query.GetAsync();
Assert.True(res is DJsonArray);
Expand Down Expand Up @@ -594,6 +644,16 @@ public async Task TestContextIssuanceCurrentYearlyRate()
Assert.True(res is DJsonValue);
}

[Fact]
public async Task TestContextIssuanceCurrentYearlyRateDetails()
{
var query = Rpc.Blocks.Head.Context.Issuance.CurrentYearlyRateDetails;
Assert.Equal($"chains/main/blocks/head/context/issuance/current_yearly_rate_details/", query.ToString());

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

[Fact]
public async Task TestContextIssuanceCurrentYearlyRateExact()
{
Expand Down Expand Up @@ -697,6 +757,16 @@ public async Task TestContextSmartRollupStakers()
Assert.True(res is DJsonArray);
}

[Fact]
public async Task TestContextTotalCurrentlyStaked()
{
var query = Rpc.Blocks.Head.Context.TotalCurrentlyStaked;
Assert.Equal($"chains/main/blocks/head/context/total_currently_staked/", query.ToString());

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

[Fact]
public async Task TestContextTotalFrozenStake()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"node": "https://rpc.tzkt.io/ithacanet/",
"node": "https://rpc.tzkt.io/ghostnet/",
"testContract": "KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5",
"testEntrypoint": "default",
"testDelegate": "tz1aWXP237BLwNHJcCD4b3DutCevhqq2T1Z9",
Expand Down
5 changes: 5 additions & 0 deletions Netezos/Rpc/Queries/ContextQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public class ContextQuery : RpcQuery
/// </summary>
public SmartRollupsQuery SmartRollups => new(this, "smart_rollups/");

/// <summary>
/// Returns the amount of staked tez by delegates, delegators or overstaked.
/// </summary>
public RpcObject TotalCurrentlyStaked => new(this, "total_currently_staked/");

/// <summary>
/// Returns the total stake (in mutez) frozen on the chain.
/// </summary>
Expand Down
27 changes: 21 additions & 6 deletions Netezos/Rpc/Queries/ContractQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ public class ContractQuery : RpcObject
public RpcObject AllTicketBalances => new(this, "all_ticket_balances/");

/// <summary>
/// Gets the query to the balance of a contract
/// Gets the query to the spendable balance of a contract (in mutez), also known as liquid balance. Corresponds
/// to tez owned by the contract that are neither staked, nor in unstaked requests, nor in frozen bonds.
/// Identical to the 'spendable' RPC.
/// </summary>
public RpcObject Balance => new(this, "balance/");

/// <summary>
/// Gets the query to the sum of the spendable balance and frozen bonds of a contract.
/// Gets the query to the sum (in mutez) of the spendable balance and frozen bonds of a contract. Corresponds
/// to the contract's full balance from which staked funds and unstake requests have been excluded. Identical
/// to the 'spendable_and_frozen_bonds' RPC.
/// </summary>
public RpcObject BalanceAndFrozenBonds => new(this, "balance_and_frozen_bonds/");

Expand Down Expand Up @@ -60,7 +64,9 @@ public class ContractQuery : RpcObject
public RpcObject FrozenBonds => new(this, "frozen_bonds/");

/// <summary>
/// Gets the query to the full balance of a contract, including frozen bonds and stake.
/// Gets the query to the full balance (in mutez) of the contract. Includes its spendable balance, staked tez,
/// unstake requests, and frozen bonds. Even if the contract is a delegate, it does not include any staked or
/// delegated tez owned by external delegators.
/// </summary>
public RpcObject FullBalance => new(this, "full_balance/");

Expand All @@ -81,15 +87,24 @@ public class ContractQuery : RpcObject
public ScriptQuery Script => new(this, "script/");

/// <summary>
/// Gets the query to the staked balance of a contract. Returns None if the contract is originated, or neither delegated nor a delegate.
/// Gets the query to the staked balance of a contract (in mutez). Returns None if the contract is originated,
/// or neither delegated nor a delegate.
/// </summary>
public RpcObject StakedBalance => new(this, "staked_balance/");

/// <summary>
/// Gets the query to the flag, indicating if the contract tokens can be spent by the manager
/// Gets the query to the spendable balance of a contract (in mutez), also known as liquid balance. Corresponds
/// to tez owned by the contract that are neither staked, nor in unstaked requests, nor in frozen bonds.
/// Identical to the 'balance' RPC.
/// </summary>
[Obsolete("This RPC query was removed. Use it on early protocols only.")]
public RpcObject Spendable => new(this, "spendable/");

/// <summary>
/// Gets the query to the sum (in mutez) of the spendable balance and frozen bonds of a contract. Corresponds
/// to the contract's full balance from which staked funds and unstake requests have been excluded. Identical
/// to the 'balance_and_frozen_bonds' RPC.
/// </summary>
public RpcObject SpendableAndFrozenBonds => new(this, "spendable_and_frozen_bonds/");

/// <summary>
/// Gets the query to the data of the contract's storage
Expand Down
Loading

0 comments on commit 439da5a

Please sign in to comment.