Skip to content

Commit

Permalink
2678 rpc ai launch cycle (#2919)
Browse files Browse the repository at this point in the history
* feat: support new rpc getAdaptiveIssuanceLaunchCycle and unit tests

re #2678

* test: add integration test and updated response type and description

* test: update test descript for clarity

* test: update estimation consumedMilligas assertion

* docs: updated docs/rpc_nodes_integration_test.md with getAdaptiveIssuanceLaunchCycle
  • Loading branch information
hui-an-yang authored Apr 17, 2024
1 parent 6047339 commit bb8a273
Show file tree
Hide file tree
Showing 15 changed files with 191 additions and 60 deletions.
99 changes: 52 additions & 47 deletions docs/rpc_nodes_integration_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,59 @@ author: Roxane Letourneau
1. The RPC nodes' integration tests are disabled by default.
Remove `./rpc-nodes.spec.ts` from `"testPathIgnorePatterns"` in the package.json.

**oxfordnet**: `npm run test:oxfordnet rpc-nodes.spec.ts`
**oxfordnet**: `npm run test:parisnet rpc-nodes.spec.ts`

**When all endpoints are accessible for a node, you will obtain:**

```
Test calling all methods from RPC node: https://a-node
✓ Verify that rpcClient.getBlockHash returns the head block hash (19 ms)
✓ Verify that rpcClient.getLiveBlocks returns the ancestors of the head block (21 ms)
✓ Verify that rpcClient.getBalance for knownBaker returns the spendable balance excluding frozen bonds (14 ms)
✓ Verify that rpcClient.getStorage for knownContract returns the data of a contract (12 ms)
✓ Verify that rpcClient.getScript for know contract returns the code and data of a contract (17 ms)
✓ Verify that rpcClient.getNormalizedScript for known contract returns the script of the contract and normalize it using the requested unparsing mode (15 ms)
✓ Verify that rpcClient.getContract returns the complete status of a contract (15 ms)
✓ Verify that rpcClient.getManagerKey for known baker returns the manager key of the contract (11 ms)
✓ Verify that rpcClient.getDelegate for known baker returns the delegate of the contract (21 ms)
✓ Verify that rpcClient.getBigMapExpr for encoded expression returns the value associated with a key in a big map (1090 ms)
✓ Verify that rpcClient.getDelegates for known baker returns information about a delegate from RPC (16 ms)
✓ Verify that rpc.getVotingInfo for known baker returns voting information about a delegate from RPC (1020 ms)
✓ Verify that rpcClient.getConstants returns all constants from RPC (18 ms)
✓ Verify that rpcClient.getBlock returns all the information about a block (24 ms)
✓ Verify that rpcClient.getBlockHeader returns whole block header (15 ms)
✓ Verify that rpcClient.getBlockMetadata returns all metadata associated to the block (17 ms)
✓ Verify that rpcClient.getBakingRights retrieves the list of delegates allowed to bake a block (14 ms)
✓ Verify that rpcClient.getAttestationRights retrieves the list of delegates allowed to attest a block (25 ms)
✓ Verify that rpcClient.getBallotList returns ballots casted so far during a voting period (10 ms)
✓ Verify that rpcClient.getBallots returns sum of ballots casted so far during a voting period (39 ms)
✓ Verify that rpcClient.getCurrentPeriod returns current period kind (11 ms)
✓ Verify that rpcClient.getCurrentProposal returns current proposal under evaluation (11 ms)
✓ Verify that rpcClient.getCurrentQuorum returns current expected quorum (13 ms)
✓ Verify that rpcClient.getVotesListings returns list of delegates with their voting weight, in number of rolls (10 ms)
✓ Verify that rpcClient.getProposals returns list of proposals with number of supporters (11 ms)
✓ Verify that rpcClient.forgeOperations forges an operation and returns the unsigned bytes (2019 ms)
✓ Verify that rpcClient.injectOperation injects an operation in node and broadcast it (11 ms)
✓ Verify that rpcClient.preapplyOperations simulates the validation of an operation (75 ms)
✓ Verify that rpcClient.getEntrypoints for known contract returns list of entrypoints of the contract (13 ms)
✓ Verify that rpcClient.getChainId returns chain ID (10 ms)
✓ Verify that rpcClient.runOperation runs an operation without signature checks (15 ms)
✓ Verify that rpcClient.simulateOperation simulates an operation without signature checks (12 ms)
✓ Verify that rpcClient.runView executes tzip4 views (29 ms)
✓ Verify that rpcClient.runScriptView executes michelson view (25 ms)
✓ Verify that rpcClient.getSuccessorPeriod will get the voting period of next block (12 ms)
✓ Verify that rpcClient.getSaplingDiffById will access the value associated with a sapling state ID (25 ms)
✓ Verify that rpcClient.getSaplingDiffByContract will access the value associated with a sapling state (10 ms)
✓ Verify that rpcClient.getProtocols will list past and present Tezos protocols (11 ms)
✓ Verify that rpcClient.getStorageUsedSpace will retrieve the used space of a contract storage (12 ms)
✓ Verify that rpcClient.getStoragePaidSpace will retrieve the paid space of a contract storage (12 ms)
✓ Verify that rpcClient.ticketBalance will retrieve the specified ticket owned by the given contract (10 ms)
✓ Verify that rpcClient.allTicketBalances will retrieve all tickets owned by the given contract (12 ms)
✓ Verify that rpcClient.getPendingOperations v1 will retrieve the pending operations in mempool with property applied (250 ms)
✓ Verify that rpcClient.getPendingOperations v2 will retrieve the pending operations in mempool with property validated (683 ms)
Test calling all methods from RPC node: http://parisnet.i.ecadinfra.com:8732/
✓ Verify that rpcClient.getBlockHash returns the head block hash (32 ms)
✓ Verify that rpcClient.getLiveBlocks returns the ancestors of the head block (48 ms)
✓ Verify that rpcClient.getBalance for knownBaker returns the spendable balance excluding frozen bonds (28 ms)
✓ Verify that rpcClient.getStorage for knownContract returns the data of a contract (27 ms)
✓ Verify that rpcClient.getScript for know contract returns the code and data of a contract (30 ms)
✓ Verify that rpcClient.getNormalizedScript for known contract returns the script of the contract and normalize it using the requested unparsing mode (61 ms)
✓ Verify that rpcClient.getContract returns the complete status of a contract (29 ms)
✓ Verify that rpcClient.getManagerKey for known baker returns the manager key of the contract (32 ms)
✓ Verify that rpcClient.getDelegate for known baker returns the delegate of the contract (27 ms)
✓ Verify that rpcClient.getBigMapExpr for encoded expression returns the value associated with a key in a big map (153 ms)
✓ Verify that rpcClient.getDelegates for known baker returns information about a delegate from RPC (31 ms)
✓ Verify that rpc.getVotingInfo for known baker returns voting information about a delegate from RPC (34 ms)
✓ Verify that rpcClient.getConstants returns all constants from RPC (28 ms)
✓ Verify that rpcClient.getBlock returns all the information about a block (52 ms)
✓ Verify that rpcClient.getBlockHeader returns whole block header (27 ms)
✓ Verify that rpcClient.getBlockMetadata returns all metadata associated to the block (30 ms)
✓ Verify that rpcClient.getBakingRights retrieves the list of delegates allowed to bake a block (28 ms)
✓ Verify that rpcClient.getAttestationRights retrieves the list of delegates allowed to attest a block (34 ms)
✓ Verify that rpcClient.getBallotList returns ballots casted so far during a voting period (26 ms)
✓ Verify that rpcClient.getBallots returns sum of ballots casted so far during a voting period (60 ms)
✓ Verify that rpcClient.getCurrentPeriod returns current period kind (57 ms)
✓ Verify that rpcClient.getCurrentProposal returns current proposal under evaluation (29 ms)
✓ Verify that rpcClient.getCurrentQuorum returns current expected quorum (29 ms)
✓ Verify that rpcClient.getVotesListings returns list of delegates with their voting weight, in number of rolls (30 ms)
✓ Verify that rpcClient.getProposals returns list of proposals with number of supporters (31 ms)
✓ Verify that rpcClient.forgeOperations forges an operation and returns the unsigned bytes (60 ms)
✓ Verify that rpcClient.injectOperation injects an operation in node and broadcast it (30 ms)
✓ Verify that rpcClient.preapplyOperations simulates the validation of an operation (100 ms)
✓ Verify that rpcClient.getEntrypoints for known contract returns list of entrypoints of the contract (27 ms)
✓ Verify that rpcClient.getChainId returns chain ID (28 ms)
✓ Verify that rpcClient.runOperation runs an operation without signature checks (29 ms)
✓ Verify that rpcClient.simulateOperation simulates an operation without signature checks (26 ms)
✓ Verify that rpcClient.runView executes tzip4 views (59 ms)
✓ Verify that rpcClient.runScriptView executes michelson view (56 ms)
✓ Verify that rpcClient.getSuccessorPeriod will get the voting period of next block (68 ms)
✓ Verify that rpcClient.getSaplingDiffById will access the value associated with a sapling state ID (56 ms)
✓ Verify that rpcClient.getSaplingDiffByContract will access the value associated with a sapling state (30 ms)
✓ Verify that rpcClient.getProtocols will list past and present Tezos protocols (26 ms)
✓ Verify that rpcClient.getStorageUsedSpace will retrieve the used space of a contract storage (26 ms)
✓ Verify that rpcClient.getStoragePaidSpace will retrieve the paid space of a contract storage (30 ms)
✓ Verify that rpcClient.ticketBalance will retrieve the specified ticket owned by the given contract (28 ms)
✓ Verify that rpcClient.allTicketBalances will retrieve all tickets owned by the given contract (32 ms)
✓ Verify that rpcClient.getAdaptiveIssuanceLaunchCycle will retrieve launch cycle 6 for http://parisnet.i.ecadinfra.com:8732/ (28 ms)
✓ Verify that rpcClient.getPendingOperations v1 will retrieve the pending operations in mempool with property applied (269 ms)
✓ Verify that rpcClient.getPendingOperations v2 will retrieve the pending operations in mempool with property validated (198 ms)
○ skipped Verify that rpcClient.getAdaptiveIssuanceLaunchCycle will retrieve launch cycle null for http://parisnet.i.ecadinfra.com:8732/
```

**Otherwise, you will see which endpoints do not work for a specific node:**
Expand Down Expand Up @@ -106,6 +109,8 @@ Test calling all methods from RPC node: https://another-node
✓ Verify that rpcClient.getStoragePaidSpace will retrieve the paid space of a contract storage (488 ms)
✓ Verify that rpcClient.ticketBalance will retrieve the specified ticket owned by the given contract (486 ms)
✓ Verify that rpcClient.allTicketBalances will retrieve all tickets owned by the given contract (561 ms)
✓ Verify that rpcClient.getPendingOperations v1 will retrieve the pending operations in mempool with property applied (1298 ms)
✓ Verify that rpcClient.getPendingOperations v2 will retrieve the pending operations in mempool with property validated (1060 ms)
✓ Verify that rpcClient.getAdaptiveIssuanceLaunchCycle will retrieve launch cycle 6 for http://parisnet.i.ecadinfra.com:8732/ (28 ms)
✓ Verify that rpcClient.getPendingOperations v1 will retrieve the pending operations in mempool with property applied (269 ms)
✓ Verify that rpcClient.getPendingOperations v2 will retrieve the pending operations in mempool with property validated (198 ms)
○ skipped Verify that rpcClient.getAdaptiveIssuanceLaunchCycle will retrieve launch cycle null for http://parisnet.i.ecadinfra.com:8732/
```
15 changes: 13 additions & 2 deletions integration-tests/__tests__/rpc/nodes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ CONFIGS().forEach(
}) => {
const Tezos = lib;
const unrestrictedRPCNode = rpc.endsWith("ecadinfra.com") ? test.skip : test;
const oxfordAndAlpha = ProtoGreaterOrEqual(protocol, Protocols.ProxfordY) ? test : test.skip;
const oxford = protocol === Protocols.ProxfordY ? test : test.skip;
const parisAndAlpha = ProtoGreaterOrEqual(protocol, Protocols.PtParisBQ) ? test : test.skip;

let ticketContract: DefaultContractType;

Expand Down Expand Up @@ -447,6 +448,16 @@ CONFIGS().forEach(
expect(ticketBalances[0].amount).toBeDefined();
});

oxford(`Verify that rpcClient.getAdaptiveIssuanceLaunchCycle will retrieve launch cycle null for ${rpc}`, async () => {
const launchCycle = await rpcClient.getAdaptiveIssuanceLaunchCycle();
expect(launchCycle).toEqual(null);
})

parisAndAlpha(`Verify that rpcClient.getAdaptiveIssuanceLaunchCycle will retrieve launch cycle 6 for ${rpc}`, async () => {
const launchCycle = await rpcClient.getAdaptiveIssuanceLaunchCycle();
expect(launchCycle).toEqual(6);
})

it('Verify that rpcClient.getPendingOperations v1 will retrieve the pending operations in mempool with property applied', async () => {
const pendingOperations = await rpcClient.getPendingOperations({ version: '1' }) as PendingOperationsV1;
expect(pendingOperations).toBeDefined();
Expand All @@ -457,7 +468,7 @@ CONFIGS().forEach(
expect(pendingOperations.branch_refused).toBeInstanceOf(Array);
});

oxfordAndAlpha('Verify that rpcClient.getPendingOperations v2 will retrieve the pending operations in mempool with property validated', async () => {
it('Verify that rpcClient.getPendingOperations v2 will retrieve the pending operations in mempool with property validated', async () => {
const pendingOperations = await rpcClient.getPendingOperations({ version: '2' }) as PendingOperationsV2;
expect(pendingOperations).toBeDefined();
expect(pendingOperations.validated).toBeInstanceOf(Array);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import {
MichelsonV1Expression,
SaplingDiffResponse,
ScriptedContracts,
AILaunchCycleResponse,
} from '@taquito/rpc';
import { ContractsLibrary } from './taquito-contracts-library';
import { BigMapQuery, BlockIdentifier, SaplingStateQuery, TzReadProvider } from '@taquito/taquito';

export class ReadWrapperContractsLibrary implements TzReadProvider {
constructor(private readProvider: TzReadProvider, private contractslibrary: ContractsLibrary) {}
constructor(
private readProvider: TzReadProvider,
private contractslibrary: ContractsLibrary
) {}

async getScript(address: string, block: BlockIdentifier): Promise<ScriptedContracts> {
const contractData = this.contractslibrary.getContract(address);
Expand Down Expand Up @@ -92,4 +96,7 @@ export class ReadWrapperContractsLibrary implements TzReadProvider {
getLiveBlocks(block: BlockIdentifier): Promise<string[]> {
return this.readProvider.getLiveBlocks(block);
}
getAdaptiveIssuanceLaunchCycle(block: BlockIdentifier): Promise<AILaunchCycleResponse> {
return this.readProvider.getAdaptiveIssuanceLaunchCycle(block);
}
}
8 changes: 7 additions & 1 deletion packages/taquito-contracts-library/src/rpc-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
PendingOperationsV2,
PendingOperationsQueryArguments,
RPCSimulateOperationParam,
AILaunchCycleResponse,
} from '@taquito/rpc';
import { ContractsLibrary } from './taquito-contracts-library';

Expand All @@ -59,7 +60,7 @@ export class RpcWrapperContractsLibrary implements RpcClientInterface {
constructor(
private rpc: RpcClientInterface,
private contractslibrary: ContractsLibrary
) { }
) {}

async getContract(
address: string,
Expand Down Expand Up @@ -319,6 +320,11 @@ export class RpcWrapperContractsLibrary implements RpcClientInterface {
): Promise<AllTicketBalances> {
return this.rpc.getAllTicketBalances(contract, { block });
}
async getAdaptiveIssuanceLaunchCycle({
block,
}: RPCOptions = defaultRPCOptions): Promise<AILaunchCycleResponse> {
return this.rpc.getAdaptiveIssuanceLaunchCycle({ block });
}
async getPendingOperations(
args: PendingOperationsQueryArguments
): Promise<PendingOperationsV1 | PendingOperationsV2> {
Expand Down
3 changes: 3 additions & 0 deletions packages/taquito-rpc/src/rpc-client-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
PendingOperationsV2,
PendingOperationsQueryArguments,
RPCSimulateOperationParam,
AILaunchCycleResponse,
} from './types';

export interface RPCOptions {
Expand Down Expand Up @@ -125,6 +126,7 @@ export interface RpcClientInterface {
options?: RPCOptions
): Promise<string>;
getAllTicketBalances(contract: string, options?: RPCOptions): Promise<AllTicketBalances>;
getAdaptiveIssuanceLaunchCycle(options?: RPCOptions): Promise<AILaunchCycleResponse>;
getPendingOperations(
args: PendingOperationsQueryArguments
): Promise<PendingOperationsV1 | PendingOperationsV2>;
Expand Down Expand Up @@ -168,5 +170,6 @@ export enum RPCMethodName {
GET_STORAGE_PAID_SPACE = 'getStoragePaidSpace',
GET_TICKET_BALANCE = 'getTicketBalance',
GET_ALL_TICKET_BALANCES = 'getAllTicketBalances',
GET_ADAPTIVE_ISSUANCE_LAUNCH_CYCLE = 'getAdaptiveIssuanceLaunchCycle',
GET_PENDING_OPERATIONS = 'getPendingOperations',
}
25 changes: 23 additions & 2 deletions packages/taquito-rpc/src/rpc-client-modules/rpc-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
PendingOperationsV1,
PendingOperationsV2,
RPCSimulateOperationParam,
AILaunchCycleResponse,
} from '../types';
import { InvalidAddressError, InvalidContractAddressError } from '@taquito/core';
import {
Expand All @@ -72,7 +73,7 @@ type RpcMethodParam =
| BigMapKey
| BakingRightsQueryArguments
| PendingOperationsQueryArguments
| AttestationRightsQueryArguments
| AttestationRightsQueryArguments;

const defaultTtl = 1000;

Expand All @@ -91,7 +92,7 @@ export class RpcClientCache implements RpcClientInterface {
constructor(
private rpcClient: RpcClientInterface,
private ttl = defaultTtl
) { }
) {}

getAllCachedData() {
return this._cache;
Expand Down Expand Up @@ -1095,6 +1096,26 @@ export class RpcClientCache implements RpcClientInterface {
return response;
}
}
/**
* @description Returns the cycle at which the launch of the Adaptive Issuance feature is set to happen. A result of null means that the feature is not yet set to launch.
* @param options contains generic configuration for rpc calls to specified block (default to head)
*/
async getAdaptiveIssuanceLaunchCycle({
block,
}: RPCOptions = defaultRPCOptions): Promise<AILaunchCycleResponse> {
const key = this.formatCacheKey(
this.rpcClient.getRpcUrl(),
RPCMethodName.GET_ADAPTIVE_ISSUANCE_LAUNCH_CYCLE,
[block]
);
if (this.has(key)) {
return this.get(key);
} else {
const response = this.rpcClient.getAdaptiveIssuanceLaunchCycle({ block });
this.put(key, response);
return response;
}
}

/**
* @description List the prevalidated operations in mempool (accessibility of mempool depends on each rpc endpoint)
Expand Down
18 changes: 17 additions & 1 deletion packages/taquito-rpc/src/taquito-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import {
PendingOperationsV1,
PendingOperationsV2,
RPCSimulateOperationParam,
AILaunchCycleResponse,
} from './types';
import { castToBigNumber } from './utils/utils';
import {
Expand Down Expand Up @@ -997,7 +998,7 @@ export class RpcClient implements RpcClientInterface {
/**
* @param contract address of the contract we want to retrieve storage information of
* @param options contains generic configuration for rpc calls to specified block (default to head)
= * @description Access the paid storage space of the contract
* @description Access the paid storage space of the contract
* @see https://tezos.gitlab.io/lima/rpc.html#get-block-id-context-contracts-contract-id-storage
*/
async getStoragePaidSpace(
Expand Down Expand Up @@ -1054,6 +1055,21 @@ export class RpcClient implements RpcClientInterface {
});
}

/**
* @description Returns the cycle at which the launch of the Adaptive Issuance feature is set to happen. A result of null means that the feature is not yet set to launch.
* @param options contains generic configuration for rpc calls to specified block (default to head)
*/
async getAdaptiveIssuanceLaunchCycle({
block,
}: { block: string } = defaultRPCOptions): Promise<AILaunchCycleResponse> {
return this.httpBackend.createRequest<AILaunchCycleResponse>({
url: this.createURL(
`/chains/${this.chain}/blocks/${block}/context/adaptive_issuance_launch_cycle`
),
method: 'GET',
});
}

/**
* @description List the prevalidated operations in mempool (accessibility of mempool depends on each rpc endpoint)
* @param args has 5 optional properties. We support version 1 as default will output { applied: { kind: endorsement} } version 2 will output { validated: { kind: attestation} }. The rest of the properties is to filter pending operations response
Expand Down
2 changes: 2 additions & 0 deletions packages/taquito-rpc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,8 @@ export interface ScriptedContracts {
storage: MichelsonV1Expression;
}

export type AILaunchCycleResponse = number | null;

export type BondId = {
smart_rollup: string;
};
Expand Down
Loading

0 comments on commit bb8a273

Please sign in to comment.