From bb8a27359bb0b3a5a06384258c555775d082552f Mon Sep 17 00:00:00 2001 From: hui-an-yang <106410553+hui-an-yang@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:13:07 -0700 Subject: [PATCH] 2678 rpc ai launch cycle (#2919) * 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 --- docs/rpc_nodes_integration_test.md | 99 ++++++++++--------- integration-tests/__tests__/rpc/nodes.spec.ts | 15 ++- .../src/read-provider-wrapper.ts | 9 +- .../src/rpc-wrapper.ts | 8 +- .../taquito-rpc/src/rpc-client-interface.ts | 3 + .../src/rpc-client-modules/rpc-cache.ts | 25 ++++- packages/taquito-rpc/src/taquito-rpc.ts | 18 +++- packages/taquito-rpc/src/types.ts | 2 + .../taquito-rpc/test/data/rpc-responses.ts | 2 + packages/taquito-rpc/test/rpc-cache.spec.ts | 13 ++- packages/taquito-rpc/test/taquito-rpc.spec.ts | 25 ++++- .../taquito/src/read-provider/interface.ts | 7 ++ .../src/read-provider/rpc-read-adapter.ts | 9 ++ packages/taquito/test/read-provider/data.ts | 2 + .../read-provider/rpc-read-adapter.spec.ts | 14 +++ 15 files changed, 191 insertions(+), 60 deletions(-) diff --git a/docs/rpc_nodes_integration_test.md b/docs/rpc_nodes_integration_test.md index 7b7d750d92..4cc44866b8 100644 --- a/docs/rpc_nodes_integration_test.md +++ b/docs/rpc_nodes_integration_test.md @@ -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:** @@ -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/ ``` \ No newline at end of file diff --git a/integration-tests/__tests__/rpc/nodes.spec.ts b/integration-tests/__tests__/rpc/nodes.spec.ts index b0a2a64c14..5b0014b356 100644 --- a/integration-tests/__tests__/rpc/nodes.spec.ts +++ b/integration-tests/__tests__/rpc/nodes.spec.ts @@ -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; @@ -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(); @@ -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); diff --git a/packages/taquito-contracts-library/src/read-provider-wrapper.ts b/packages/taquito-contracts-library/src/read-provider-wrapper.ts index c02635bcab..2c6be8cbb3 100644 --- a/packages/taquito-contracts-library/src/read-provider-wrapper.ts +++ b/packages/taquito-contracts-library/src/read-provider-wrapper.ts @@ -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 { const contractData = this.contractslibrary.getContract(address); @@ -92,4 +96,7 @@ export class ReadWrapperContractsLibrary implements TzReadProvider { getLiveBlocks(block: BlockIdentifier): Promise { return this.readProvider.getLiveBlocks(block); } + getAdaptiveIssuanceLaunchCycle(block: BlockIdentifier): Promise { + return this.readProvider.getAdaptiveIssuanceLaunchCycle(block); + } } diff --git a/packages/taquito-contracts-library/src/rpc-wrapper.ts b/packages/taquito-contracts-library/src/rpc-wrapper.ts index 438e5bf4d0..9ea34277d8 100644 --- a/packages/taquito-contracts-library/src/rpc-wrapper.ts +++ b/packages/taquito-contracts-library/src/rpc-wrapper.ts @@ -48,6 +48,7 @@ import { PendingOperationsV2, PendingOperationsQueryArguments, RPCSimulateOperationParam, + AILaunchCycleResponse, } from '@taquito/rpc'; import { ContractsLibrary } from './taquito-contracts-library'; @@ -59,7 +60,7 @@ export class RpcWrapperContractsLibrary implements RpcClientInterface { constructor( private rpc: RpcClientInterface, private contractslibrary: ContractsLibrary - ) { } + ) {} async getContract( address: string, @@ -319,6 +320,11 @@ export class RpcWrapperContractsLibrary implements RpcClientInterface { ): Promise { return this.rpc.getAllTicketBalances(contract, { block }); } + async getAdaptiveIssuanceLaunchCycle({ + block, + }: RPCOptions = defaultRPCOptions): Promise { + return this.rpc.getAdaptiveIssuanceLaunchCycle({ block }); + } async getPendingOperations( args: PendingOperationsQueryArguments ): Promise { diff --git a/packages/taquito-rpc/src/rpc-client-interface.ts b/packages/taquito-rpc/src/rpc-client-interface.ts index af9e2f8edd..76864ed912 100644 --- a/packages/taquito-rpc/src/rpc-client-interface.ts +++ b/packages/taquito-rpc/src/rpc-client-interface.ts @@ -48,6 +48,7 @@ import { PendingOperationsV2, PendingOperationsQueryArguments, RPCSimulateOperationParam, + AILaunchCycleResponse, } from './types'; export interface RPCOptions { @@ -125,6 +126,7 @@ export interface RpcClientInterface { options?: RPCOptions ): Promise; getAllTicketBalances(contract: string, options?: RPCOptions): Promise; + getAdaptiveIssuanceLaunchCycle(options?: RPCOptions): Promise; getPendingOperations( args: PendingOperationsQueryArguments ): Promise; @@ -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', } diff --git a/packages/taquito-rpc/src/rpc-client-modules/rpc-cache.ts b/packages/taquito-rpc/src/rpc-client-modules/rpc-cache.ts index 2fe8b79d73..a4712e7bb2 100644 --- a/packages/taquito-rpc/src/rpc-client-modules/rpc-cache.ts +++ b/packages/taquito-rpc/src/rpc-client-modules/rpc-cache.ts @@ -50,6 +50,7 @@ import { PendingOperationsV1, PendingOperationsV2, RPCSimulateOperationParam, + AILaunchCycleResponse, } from '../types'; import { InvalidAddressError, InvalidContractAddressError } from '@taquito/core'; import { @@ -72,7 +73,7 @@ type RpcMethodParam = | BigMapKey | BakingRightsQueryArguments | PendingOperationsQueryArguments - | AttestationRightsQueryArguments + | AttestationRightsQueryArguments; const defaultTtl = 1000; @@ -91,7 +92,7 @@ export class RpcClientCache implements RpcClientInterface { constructor( private rpcClient: RpcClientInterface, private ttl = defaultTtl - ) { } + ) {} getAllCachedData() { return this._cache; @@ -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 { + 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) diff --git a/packages/taquito-rpc/src/taquito-rpc.ts b/packages/taquito-rpc/src/taquito-rpc.ts index db882d926b..76d8a2db5c 100644 --- a/packages/taquito-rpc/src/taquito-rpc.ts +++ b/packages/taquito-rpc/src/taquito-rpc.ts @@ -66,6 +66,7 @@ import { PendingOperationsV1, PendingOperationsV2, RPCSimulateOperationParam, + AILaunchCycleResponse, } from './types'; import { castToBigNumber } from './utils/utils'; import { @@ -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( @@ -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 { + return this.httpBackend.createRequest({ + 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 diff --git a/packages/taquito-rpc/src/types.ts b/packages/taquito-rpc/src/types.ts index 16d880da8f..b399bc0f78 100644 --- a/packages/taquito-rpc/src/types.ts +++ b/packages/taquito-rpc/src/types.ts @@ -1246,6 +1246,8 @@ export interface ScriptedContracts { storage: MichelsonV1Expression; } +export type AILaunchCycleResponse = number | null; + export type BondId = { smart_rollup: string; }; diff --git a/packages/taquito-rpc/test/data/rpc-responses.ts b/packages/taquito-rpc/test/data/rpc-responses.ts index 21fc5de7f3..5f4258170a 100644 --- a/packages/taquito-rpc/test/data/rpc-responses.ts +++ b/packages/taquito-rpc/test/data/rpc-responses.ts @@ -4312,6 +4312,8 @@ export const ticketBalancesResponse = [ }, ]; +export const aiLaunchCycle = 6; + export const pendingOperationsResponse = { applied: [ { diff --git a/packages/taquito-rpc/test/rpc-cache.spec.ts b/packages/taquito-rpc/test/rpc-cache.spec.ts index 208df91adf..6e832637d7 100644 --- a/packages/taquito-rpc/test/rpc-cache.spec.ts +++ b/packages/taquito-rpc/test/rpc-cache.spec.ts @@ -32,6 +32,7 @@ import { constants, ticketBalancesResponse, pendingOperationsResponse, + aiLaunchCycle, } from './data/rpc-responses'; /** @@ -87,6 +88,7 @@ describe('RpcClientCache test', () => { getProtocols: jest.fn(), getTicketBalance: jest.fn(), getAllTicketBalances: jest.fn(), + getAdaptiveIssuanceLaunchCycle: jest.fn(), getPendingOperations: jest.fn(), }; @@ -125,6 +127,7 @@ describe('RpcClientCache test', () => { mockRpcClient.getProtocols.mockReturnValue(protocols); mockRpcClient.getTicketBalance.mockReturnValue('3'); mockRpcClient.getAllTicketBalances.mockReturnValue(ticketBalancesResponse); + mockRpcClient.getAdaptiveIssuanceLaunchCycle.mockReturnValue(aiLaunchCycle); mockRpcClient.getPendingOperations.mockReturnValue(pendingOperationsResponse); rpcCache = new RpcClientCache(mockRpcClient); }); @@ -176,6 +179,7 @@ describe('RpcClientCache test', () => { content: { string: 'ticket1' }, }); await rpcCache.getAllTicketBalances(contractAddress); + await rpcCache.getAdaptiveIssuanceLaunchCycle(); await rpcCache.getPendingOperations(); expect(rpcCache.getAllCachedData()['rpcTest/getBlockHash/head/'].response).toEqual(blockHash); @@ -266,6 +270,9 @@ describe('RpcClientCache test', () => { expect( rpcCache.getAllCachedData()[`rpcTest/getAllTicketBalances/head/${contractAddress}/`].response ).toEqual(ticketBalancesResponse); + expect( + rpcCache.getAllCachedData()['rpcTest/getAdaptiveIssuanceLaunchCycle/head/'].response + ).toEqual(aiLaunchCycle); expect(rpcCache.getAllCachedData()[`rpcTest/getPendingOperations/{}/`].response).toEqual( pendingOperationsResponse ); @@ -324,6 +331,7 @@ describe('RpcClientCache test', () => { block ); await rpcCache.getAllTicketBalances(contractAddress, block); + await rpcCache.getAdaptiveIssuanceLaunchCycle(block); expect(rpcCache.getAllCachedData()[`rpcTest/getBlockHash/${block.block}/`].response).toEqual( blockHash @@ -433,7 +441,9 @@ describe('RpcClientCache test', () => { rpcCache.getAllCachedData()[`rpcTest/getAllTicketBalances/${block.block}/${contractAddress}/`] .response ).toEqual(ticketBalancesResponse); - + expect( + rpcCache.getAllCachedData()[`rpcTest/getAdaptiveIssuanceLaunchCycle/${block.block}/`].response + ).toEqual(aiLaunchCycle); rpcCache.deleteAllCachedData(); }); @@ -475,6 +485,7 @@ describe('RpcClientCache test', () => { await rpcCache.getProtocols(); await rpcCache.getTicketBalance(contractAddress, ticketToken); await rpcCache.getAllTicketBalances(contractAddress); + await rpcCache.getAdaptiveIssuanceLaunchCycle(); await rpcCache.getPendingOperations(); rpcCache.deleteAllCachedData(); diff --git a/packages/taquito-rpc/test/taquito-rpc.spec.ts b/packages/taquito-rpc/test/taquito-rpc.spec.ts index b6d2e7c5b5..dd360a5d71 100644 --- a/packages/taquito-rpc/test/taquito-rpc.spec.ts +++ b/packages/taquito-rpc/test/taquito-rpc.spec.ts @@ -57,6 +57,7 @@ import { smartRollupRefuteResponse, smartRollupRecoverBondResponse, smartRollupTimeoutResponse, + aiLaunchCycle, } from './data/rpc-responses'; /** @@ -3320,8 +3321,8 @@ describe('RpcClient test', () => { const balanceUpdate = 'metadata' in response.contents[0] ? (response.contents[0]['metadata'][ - 'balance_updates' - ] as OperationMetadataBalanceUpdates[]) + 'balance_updates' + ] as OperationMetadataBalanceUpdates[]) : []; expect(balanceUpdate![0]['category']).toEqual( METADATA_BALANCE_UPDATES_CATEGORY.BAKING_BONUSES @@ -3378,8 +3379,8 @@ describe('RpcClient test', () => { const balanceUpdate = 'metadata' in response.contents[0] ? (response.contents[0]['metadata'][ - 'balance_updates' - ] as OperationMetadataBalanceUpdates[]) + 'balance_updates' + ] as OperationMetadataBalanceUpdates[]) : []; expect(balanceUpdate![0]['category']).toEqual( METADATA_BALANCE_UPDATES_CATEGORY.BAKING_REWARDS @@ -3982,8 +3983,22 @@ describe('RpcClient test', () => { }); }); + describe('AdaptiveIssuanceLaunchCycle', () => { + it('should query the right url and data', async () => { + httpBackend.createRequest.mockResolvedValue(aiLaunchCycle); + const response = await client.getAdaptiveIssuanceLaunchCycle(); + + expect(httpBackend.createRequest.mock.calls[0][0]).toEqual({ + method: 'GET', + url: `root/chains/test/blocks/head/context/adaptive_issuance_launch_cycle`, + }); + + expect(response).toEqual(aiLaunchCycle); + }); + }); + describe('getPendingOperations', () => { - it('should query the correct url and retrun pending operations in mempool', async () => { + it('should query the correct url and return pending operations in mempool', async () => { httpBackend.createRequest.mockReturnValue(Promise.resolve(pendingOperationsResponse)); const response: PendingOperationsV1 | PendingOperationsV2 = await client.getPendingOperations(); diff --git a/packages/taquito/src/read-provider/interface.ts b/packages/taquito/src/read-provider/interface.ts index 6a7ba42df8..d92b6ea4d6 100644 --- a/packages/taquito/src/read-provider/interface.ts +++ b/packages/taquito/src/read-provider/interface.ts @@ -4,6 +4,7 @@ import { MichelsonV1Expression, SaplingDiffResponse, ScriptedContracts, + AILaunchCycleResponse, } from '@taquito/rpc'; import BigNumber from 'bignumber.js'; @@ -151,4 +152,10 @@ export interface TzReadProvider { * @param block from which we want to retrieve the information */ getLiveBlocks(block: BlockIdentifier): Promise; + + /** + * @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 block from which we want to retrieve the information + */ + getAdaptiveIssuanceLaunchCycle(block: BlockIdentifier): Promise; } diff --git a/packages/taquito/src/read-provider/rpc-read-adapter.ts b/packages/taquito/src/read-provider/rpc-read-adapter.ts index 83e3c492e0..c1a1850176 100644 --- a/packages/taquito/src/read-provider/rpc-read-adapter.ts +++ b/packages/taquito/src/read-provider/rpc-read-adapter.ts @@ -5,6 +5,7 @@ import { RpcClientInterface, SaplingDiffResponse, ScriptedContracts, + AILaunchCycleResponse, } from '@taquito/rpc'; import BigNumber from 'bignumber.js'; import { BigMapQuery, BlockIdentifier, SaplingStateQuery, TzReadProvider } from './interface'; @@ -212,4 +213,12 @@ export class RpcReadAdapter implements TzReadProvider { getLiveBlocks(block: BlockIdentifier): Promise { return this.rpc.getLiveBlocks({ block: String(block) }); } + + /** + * @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 block from which we want to retrieve the information + */ + getAdaptiveIssuanceLaunchCycle(block: BlockIdentifier): Promise { + return this.rpc.getAdaptiveIssuanceLaunchCycle({ block: String(block) }); + } } diff --git a/packages/taquito/test/read-provider/data.ts b/packages/taquito/test/read-provider/data.ts index b2b6b4465c..73c00f63d9 100644 --- a/packages/taquito/test/read-provider/data.ts +++ b/packages/taquito/test/read-provider/data.ts @@ -720,3 +720,5 @@ export const liveBlocks = [ 'BMcczQyMnGAzM2WJPQ2vbgyzryg52GQgNWLggpHDKPqhQzJUeT8', 'BMdaQruY6gep3cmRwGoxEUqx2XJ79XQKqpTT7jusKLA1bSTowRc', ]; + +export const aiLaunchCycle = 6; diff --git a/packages/taquito/test/read-provider/rpc-read-adapter.spec.ts b/packages/taquito/test/read-provider/rpc-read-adapter.spec.ts index a4498e9d79..276c798c91 100644 --- a/packages/taquito/test/read-provider/rpc-read-adapter.spec.ts +++ b/packages/taquito/test/read-provider/rpc-read-adapter.spec.ts @@ -11,6 +11,7 @@ import { contractResponse, contractStorage, liveBlocks, + aiLaunchCycle, saplingState, } from './data'; import { RpcClient } from '@taquito/rpc'; @@ -34,6 +35,7 @@ describe('RpcReadAdapter test', () => { getManagerKey: jest.Mock; getBlock: jest.Mock; getLiveBlocks: jest.Mock; + getAdaptiveIssuanceLaunchCycle: jest.Mock; }; beforeEach(() => { @@ -54,6 +56,7 @@ describe('RpcReadAdapter test', () => { getManagerKey: jest.fn(), getBlock: jest.fn(), getLiveBlocks: jest.fn(), + getAdaptiveIssuanceLaunchCycle: jest.fn(), }; readProvider = new RpcReadAdapter(mockRpcClient as any); }); @@ -289,6 +292,17 @@ describe('RpcReadAdapter test', () => { expect(mockRpcClient.getLiveBlocks.mock.calls[0][0]).toEqual({ block: `${block}` }); }); + + it(`should get adaptive issuance launch cycle at block: ${block}`, async () => { + mockRpcClient.getAdaptiveIssuanceLaunchCycle.mockResolvedValue(aiLaunchCycle); + + const result = await readProvider.getAdaptiveIssuanceLaunchCycle(block); + expect(result).toEqual(aiLaunchCycle); + + expect(mockRpcClient.getAdaptiveIssuanceLaunchCycle.mock.calls[0][0]).toEqual({ + block: `${block}`, + }); + }); }); it(`should get the chain id`, async () => {