From 009c7ef85fb945bc0cb6857a9694d9df2ea27f8a Mon Sep 17 00:00:00 2001 From: hui-an-yang <106410553+hui-an-yang@users.noreply.github.com> Date: Tue, 14 Feb 2023 16:43:01 -0800 Subject: [PATCH] 2270 support new rpc endpoint ticket balance and all ticket balance (#2313) * feat: support new rpc endpoint ticket_balance re #2270 * feat: support new rpc endpoint all_ticket_balances re #2270 * fix: changed http method of all_ticket_balances to get re #2270 * fix: type definition mistake re #2270 * docs: updated docs for getTicketBalance rpc endpoint #2270 * fix: remove // in formatCacheKey when passed rpcMethodData and updated doc re #2270 * test: added rpc endpoint ticketBalance and allTicketBalances unit test re #2270 * test: added rpc endpoint ticketBalance and allTicketBalances integration test re #2270 * fix: added mumbai protocol to have empty txRollupAddress in known-contracts file * fix: correct misused of rpcMethodParams in RpcClientCache * style: address comment to keep type names uppercase re #2270 * test: removed not needed contract code and use code_with_ticket.ts instead re #2270 * test: removed console.log re #2270 * test: added try catch when originating contract and removed non-null assertion re #2270 * test: removed all tx_rollup references out of integration-tests * test: removed more tx rollup references in integration tests and some styles and doc update re #2270 * style: addressed comments regard style and docs * style: fixed ci run error * test: added more assertion to integration test * test: added array assertion for getAllTicketBalances result re #2270 * ci: added flextesa mumbaibox to ci run * fix: fix ci run * revert: revert ci changes and update integration test to target correct testnet --- integration-tests/config.ts | 41 +------- ...contract-tx-rollup-batch-operation.spec.ts | 73 -------------- ...ct-tx-rollup-origination-operation.spec.ts | 65 ------------- .../contract-tx-wait-2-confirmations.spec.ts | 24 ----- integration-tests/data/allTestsCases.ts | 54 ----------- .../data/contract_origination.ts | 64 ------------- .../data/tickets_deposit_contract.ts | 20 ---- ...iple-manager-operations-in-a-block.spec.ts | 4 +- integration-tests/ledger-signer.spec.ts | 2 +- .../originate-known-contracts.ts | 24 +---- integration-tests/prepare-operation.spec.ts | 13 --- integration-tests/rpc-nodes.spec.ts | 53 +++++++---- integration-tests/sandbox-env.sh | 4 +- .../tx-rollup-l2-address.spec.ts | 95 ------------------- .../src/rpc-wrapper.ts | 15 +++ .../taquito-rpc/src/rpc-client-interface.ts | 10 ++ .../src/rpc-client-modules/rpc-cache.ts | 83 +++++++++++++--- packages/taquito-rpc/src/taquito-rpc.ts | 46 +++++++++ packages/taquito-rpc/src/types.ts | 15 +++ .../taquito-rpc/test/data/rpc-responses.ts | 13 +++ packages/taquito-rpc/test/rpc-cache.spec.ts | 46 ++++++++- packages/taquito-rpc/test/taquito-rpc.spec.ts | 35 +++++++ 22 files changed, 297 insertions(+), 502 deletions(-) delete mode 100644 integration-tests/contract-tx-rollup-batch-operation.spec.ts delete mode 100644 integration-tests/contract-tx-rollup-origination-operation.spec.ts delete mode 100644 integration-tests/contract-tx-wait-2-confirmations.spec.ts delete mode 100644 integration-tests/data/tickets_deposit_contract.ts delete mode 100644 integration-tests/tx-rollup-l2-address.spec.ts diff --git a/integration-tests/config.ts b/integration-tests/config.ts index 93c48d4773..22ecf1fc4e 100644 --- a/integration-tests/config.ts +++ b/integration-tests/config.ts @@ -4,10 +4,10 @@ import { HttpBackend } from '@taquito/http-utils'; import { b58cencode, Prefix, prefix } from '@taquito/utils'; import { importKey, InMemorySigner } from '@taquito/signer'; import { RpcClient, RpcClientCache } from '@taquito/rpc'; -import { knownBigMapContractProtoALph, knownContractProtoALph, knownOnChainViewContractAddressProtoALph, knownSaplingContractProtoALph, knownTzip12BigMapOffChainContractProtoALph, txRollupAddressProtoALph } from './known-contracts-ProtoALph'; -import { knownContractPtLimaPtL, knownBigMapContractPtLimaPtL, knownTzip12BigMapOffChainContractPtLimaPtL, knownSaplingContractPtLimaPtL, knownOnChainViewContractAddressPtLimaPtL, txRollupAddressPtLimaPtL } from './known-contracts-PtLimaPtL'; -import { knownContractPtGhostnet, knownBigMapContractPtGhostnet, knownTzip12BigMapOffChainContractPtGhostnet, knownSaplingContractPtGhostnet, knownOnChainViewContractAddressPtGhostnet, txRollupAddressPtGhostnet } from './known-contracts-PtGhostnet'; -import { knownContractPtMumbaii, knownBigMapContractPtMumbaii, knownTzip12BigMapOffChainContractPtMumbaii, knownSaplingContractPtMumbaii, knownOnChainViewContractAddressPtMumbaii, txRollupAddressPtMumbaii } from './known-contracts-PtMumbaii'; +import { knownBigMapContractProtoALph, knownContractProtoALph, knownOnChainViewContractAddressProtoALph, knownSaplingContractProtoALph, knownTzip12BigMapOffChainContractProtoALph } from './known-contracts-ProtoALph'; +import { knownContractPtLimaPtL, knownBigMapContractPtLimaPtL, knownTzip12BigMapOffChainContractPtLimaPtL, knownSaplingContractPtLimaPtL, knownOnChainViewContractAddressPtLimaPtL } from './known-contracts-PtLimaPtL'; +import { knownContractPtGhostnet, knownBigMapContractPtGhostnet, knownTzip12BigMapOffChainContractPtGhostnet, knownSaplingContractPtGhostnet, knownOnChainViewContractAddressPtGhostnet } from './known-contracts-PtGhostnet'; +import { knownContractPtMumbaii, knownBigMapContractPtMumbaii, knownTzip12BigMapOffChainContractPtMumbaii, knownSaplingContractPtMumbaii, knownOnChainViewContractAddressPtMumbaii } from './known-contracts-PtMumbaii'; const nodeCrypto = require('crypto'); @@ -35,9 +35,6 @@ interface Config { knownTzip1216Contract: string; knownSaplingContract: string; knownViewContract: string; - txRollupWithdrawContract: string; - txRollupDepositContract: string; - txRollupAddress: string; protocol: Protocols; signerConfig: EphemeralConfig | SecretKeyConfig; } @@ -85,10 +82,7 @@ const limanetEphemeral = { knownBigMapContract: process.env['TEZOS_LIMANET_BIGMAPCONTRACT_ADDRESS'] || knownBigMapContractPtLimaPtL, knownTzip1216Contract: process.env['TEZOS_LIMANET_TZIP1216CONTRACT_ADDRESS'] || knownTzip12BigMapOffChainContractPtLimaPtL, knownSaplingContract: process.env['TEZOS_LIMANET_SAPLINGCONTRACT_ADDRESS'] || knownSaplingContractPtLimaPtL, - txRollupWithdrawContract: process.env['TEZOS_LIMANET_TX_ROLLUP_WITHDRAW_CONTRACT'] || '', - txRollupDepositContract: process.env['TEZOS_LIMANET_TX_ROLLUP_DEPOSIT_CONTRACT'] || '', knownViewContract: process.env['TEZOS_LIMANET_ON_CHAIN_VIEW_CONTRACT'] || knownOnChainViewContractAddressPtLimaPtL, - txRollupAddress: process.env['TEZOS_LIMANET_TXROLLUP_ADDRESS'] || txRollupAddressPtLimaPtL, protocol: Protocols.PtLimaPtL, signerConfig: { type: SignerType.EPHEMERAL_KEY as SignerType.EPHEMERAL_KEY, @@ -106,10 +100,7 @@ const mumbainetEphemeral = { knownBigMapContract: process.env['TEZOS_MUMBAINET_BIGMAPCONTRACT_ADDRESS'] || knownBigMapContractPtMumbaii, knownTzip1216Contract: process.env['TEZOS_MUMBAINET_TZIP1216CONTRACT_ADDRESS'] || knownTzip12BigMapOffChainContractPtMumbaii, knownSaplingContract: process.env['TEZOS_MUMBAINET_SAPLINGCONTRACT_ADDRESS'] || knownSaplingContractPtMumbaii, - txRollupWithdrawContract: process.env['TEZOS_MUMBAINET_TX_ROLLUP_WITHDRAW_CONTRACT'] || '', - txRollupDepositContract: process.env['TEZOS_MUMBAINET_TX_ROLLUP_DEPOSIT_CONTRACT'] || '', knownViewContract: process.env['TEZOS_MUMBAINET_ON_CHAIN_VIEW_CONTRACT'] || knownOnChainViewContractAddressPtMumbaii, - txRollupAddress: process.env['TEZOS_MUMBAINET_TXROLLUP_ADDRESS'] || txRollupAddressPtMumbaii, protocol: Protocols.PtMumbaii, signerConfig: { type: SignerType.EPHEMERAL_KEY as SignerType.EPHEMERAL_KEY, @@ -127,10 +118,7 @@ const ghostnetEphemeral = { knownBigMapContract: process.env['TEZOS_GHOSTNET_BIGMAPCONTRACT_ADDRESS'] || knownBigMapContractPtGhostnet, knownTzip1216Contract: process.env['TEZOS_GHOSTNET_TZIP1216CONTRACT_ADDRESS'] || knownTzip12BigMapOffChainContractPtGhostnet, knownSaplingContract: process.env['TEZOS_GHOSTNET_SAPLINGCONTRACT_ADDRESS'] || knownSaplingContractPtGhostnet, - txRollupWithdrawContract: process.env['TEZOS_GHOSTNET_TX_ROLLUP_WITHDRAW_CONTRACT'] || '', - txRollupDepositContract: process.env['TEZOS_GHOSTNET_TX_ROLLUP_DEPOSIT_CONTRACT'] || '', knownViewContract: process.env['TEZOS_GHOSTNET_ON_CHAIN_VIEW_CONTRACT'] || knownOnChainViewContractAddressPtGhostnet, - txRollupAddress: process.env['TEZOS_GHOSTANET_TXROLLUP_ADDRESS'] || txRollupAddressPtGhostnet, protocol: Protocols.PtLimaPtL, signerConfig: { type: SignerType.EPHEMERAL_KEY as SignerType.EPHEMERAL_KEY, @@ -148,10 +136,7 @@ const mondaynetEphemeral = { knownBigMapContract: process.env['TEZOS_MONDAYNET_BIGMAPCONTRACT_ADDRESS'] || knownBigMapContractProtoALph, knownTzip1216Contract: process.env['TEZOS_MONDAYNET_TZIP1216CONTRACT_ADDRESS'] || knownTzip12BigMapOffChainContractProtoALph, knownSaplingContract: process.env['TEZOS_MONDAYNET_SAPLINGCONTRACT_ADDRESS'] || knownSaplingContractProtoALph, - txRollupWithdrawContract: process.env['TX_ROLLUP_WITHDRAW_CONTRACT'] || '', - txRollupDepositContract: process.env['TX_ROLLUP_DEPOSIT_CONTRACT'] || '', knownViewContract: process.env['TEZOS_MONDAYNET_ON_CHAIN_VIEW_CONTRACT'] || knownOnChainViewContractAddressProtoALph, - txRollupAddress: process.env['TEZOS_MONDAYNET_TXROLLUP_ADDRESS'] || txRollupAddressProtoALph, protocol: Protocols.ProtoALpha, signerConfig: { type: SignerType.EPHEMERAL_KEY as SignerType.EPHEMERAL_KEY, @@ -169,10 +154,7 @@ const limanetSecretKey = { knownBigMapContract: process.env['TEZOS_LIMANET_BIGMAPCONTRACT_ADDRESS'] || knownBigMapContractPtLimaPtL, knownTzip1216Contract: process.env['TEZOS_LIMANET_TZIP1216CONTRACT_ADDRESS'] || knownTzip12BigMapOffChainContractPtLimaPtL, knownSaplingContract: process.env['TEZOS_LIMANET_SAPLINGCONTRACT_ADDRESS'] || knownSaplingContractPtLimaPtL, - txRollupWithdrawContract: process.env['TEZOS_LIMANET_TX_ROLLUP_WITHDRAW_CONTRACT'] || '', - txRollupDepositContract: process.env['TEZOS_LIMANET_TX_ROLLUP_DEPOSIT_CONTRACT'] || '', knownViewContract: process.env['TEZOS_LIMANET_ON_CHAIN_VIEW_CONTRACT'] || knownOnChainViewContractAddressPtLimaPtL, - txRollupAddress: process.env['TEZOS_LIMANET_TXROLLUP_ADDRESS'] || txRollupAddressPtLimaPtL, protocol: Protocols.PtLimaPtL, signerConfig: defaultSecretKey }; @@ -186,10 +168,7 @@ const mumbainetSecretKey = { knownBigMapContract: process.env['TEZOS_MUMBAINET_BIGMAPCONTRACT_ADDRESS'] || knownBigMapContractPtMumbaii, knownTzip1216Contract: process.env['TEZOS_MUMBAINET_TZIP1216CONTRACT_ADDRESS'] || knownTzip12BigMapOffChainContractPtMumbaii, knownSaplingContract: process.env['TEZOS_MUMBAINET_SAPLINGCONTRACT_ADDRESS'] || knownSaplingContractPtMumbaii, - txRollupWithdrawContract: process.env['TEZOS_MUMBAINET_TX_ROLLUP_WITHDRAW_CONTRACT'] || '', - txRollupDepositContract: process.env['TEZOS_MUMBAINET_TX_ROLLUP_DEPOSIT_CONTRACT'] || '', knownViewContract: process.env['TEZOS_MUMBAINET_ON_CHAIN_VIEW_CONTRACT'] || knownOnChainViewContractAddressPtMumbaii, - txRollupAddress: process.env['TEZOS_MUMBAINET_TXROLLUP_ADDRESS'] || txRollupAddressPtMumbaii, protocol: Protocols.PtMumbaii, signerConfig: defaultSecretKey }; @@ -203,10 +182,7 @@ const ghostnetSecretKey = { knownBigMapContract: process.env['TEZOS_GHOSTNET_BIGMAPCONTRACT_ADDRESS'] || knownBigMapContractPtGhostnet, knownTzip1216Contract: process.env['TEZOS_GHOSTNET_TZIP1216CONTRACT_ADDRESS'] || knownTzip12BigMapOffChainContractPtGhostnet, knownSaplingContract: process.env['TEZOS_GHOSTNET_SAPLINGCONTRACT_ADDRESS'] || knownSaplingContractPtGhostnet, - txRollupWithdrawContract: process.env['TEZOS_GHOSTNET_TX_ROLLUP_WITHDRAW_CONTRACT'] || '', - txRollupDepositContract: process.env['TEZOS_GHOSTNET_TX_ROLLUP_DEPOSIT_CONTRACT'] || '', knownViewContract: process.env['TEZOS_GHOSTNET_ON_CHAIN_VIEW_CONTRACT'] || knownOnChainViewContractAddressPtGhostnet, - txRollupAddress: process.env['TEZOS_GHOSTNET_TXROLLUP_ADDRESS'] || txRollupAddressPtGhostnet, protocol: Protocols.PtLimaPtL, signerConfig: defaultSecretKey }; @@ -220,10 +196,7 @@ const mondaynetSecretKey = { knownBigMapContract: process.env['TEZOS_MONDAYNET_BIGMAPCONTRACT_ADDRESS'] || knownBigMapContractProtoALph, knownTzip1216Contract: process.env['TEZOS_MONDAYNET_TZIP1216CONTRACT_ADDRESS'] || knownTzip12BigMapOffChainContractProtoALph, knownSaplingContract: process.env['TEZOS_MONDAYNET_SAPLINGCONTRACT_ADDRESS'] || knownSaplingContractProtoALph, - txRollupWithdrawContract: process.env['TX_ROLLUP_WITHDRAW_CONTRACT'] || '', - txRollupDepositContract: process.env['TX_ROLLUP_DEPOSIT_CONTRACT'] || '', knownViewContract: process.env['TEZOS_MONDAYNET_ON_CHAIN_VIEW_CONTRACT'] || knownOnChainViewContractAddressProtoALph, - txRollupAddress: process.env['TEZOS_MONDAYNET_TXROLLUP_ADDRESS'] || txRollupAddressProtoALph, protocol: Protocols.ProtoALpha, signerConfig: defaultSecretKey }; @@ -338,10 +311,7 @@ export const CONFIGS = () => { knownTzip1216Contract, knownSaplingContract, knownViewContract, - txRollupAddress, signerConfig, - txRollupDepositContract, - txRollupWithdrawContract, }) => { const Tezos = configureRpcCache(rpc, rpcCacheMilliseconds); @@ -362,10 +332,7 @@ export const CONFIGS = () => { knownTzip1216Contract, knownSaplingContract, knownViewContract, - txRollupAddress, signerConfig, - txRollupDepositContract, - txRollupWithdrawContract, setup: async (preferFreshKey: boolean = false) => { if (signerConfig.type === SignerType.SECRET_KEY) { setupWithSecretKey(Tezos, signerConfig); diff --git a/integration-tests/contract-tx-rollup-batch-operation.spec.ts b/integration-tests/contract-tx-rollup-batch-operation.spec.ts deleted file mode 100644 index 89b188acda..0000000000 --- a/integration-tests/contract-tx-rollup-batch-operation.spec.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { CONFIGS } from "./config"; -import { OpKind, Protocols } from "@taquito/taquito"; - - -CONFIGS().forEach(({ lib, rpc, setup, protocol, txRollupAddress }) => { - const Tezos = lib; - - const Limanet = protocol === Protocols.PtLimaPtL ? it : it.skip; - describe(`Test tx rollup batch using: ${rpc}`, () => { - - beforeEach(async (done) => { - await setup(true); - done(); - }); - Limanet('should succeed to submit a tx rollup batch with auto-estimate of the fees', async (done) => { - const op = await Tezos.contract.txRollupSubmitBatch({ - content: '626c6f62', - rollup: txRollupAddress - }); - await op.confirmation(2); - expect(op.hash).toBeDefined(); - expect(op.content).toEqual('626c6f62'); - expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY); - expect(op.status).toBe('applied'); - expect(Number(op.consumedGas)).toBeGreaterThan(0); - - done(); - }); - - Limanet('should succeed to submit a tx rollup batch with defined fees', async (done) => { - const op = await Tezos.contract.txRollupSubmitBatch({ - content: '626c6f62', - rollup: txRollupAddress, - storageLimit: 6000, - gasLimit: 3000, - fee: 500 - }); - await op.confirmation(2); - expect(op.hash).toBeDefined(); - expect(op.content).toEqual('626c6f62'); - expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY); - expect(op.status).toBe('applied'); - - done(); - }); - - Limanet('should succeed to include a tx rollup batch operation in a batch', async (done) => { - const op = await Tezos.contract.batch([ - { kind: OpKind.TRANSACTION, to: 'tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu', amount: 0.02 }, - { kind: OpKind.TX_ROLLUP_SUBMIT_BATCH, content: '626c6f62', rollup: txRollupAddress, } - ]).send(); - await op.confirmation(2); - expect(op.hash).toBeDefined(); - expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY); - expect(op.status).toBe('applied'); - - done(); - }); - - Limanet('should succeed to include a tx rollup batch operation in a batch using `with` method', async (done) => { - const op = await Tezos.contract.batch() - .withTransfer({ to: 'tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu', amount: 0.02 }) - .withTxRollupSubmitBatch({ content: '626c6f62', rollup: txRollupAddress }) - .send(); - await op.confirmation(); - expect(op.hash).toBeDefined(); - expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY); - expect(op.status).toBe('applied'); - - done(); - }); - }); -}); diff --git a/integration-tests/contract-tx-rollup-origination-operation.spec.ts b/integration-tests/contract-tx-rollup-origination-operation.spec.ts deleted file mode 100644 index d320216846..0000000000 --- a/integration-tests/contract-tx-rollup-origination-operation.spec.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { CONFIGS } from "./config"; -import { OpKind, Protocols } from "@taquito/taquito"; - -CONFIGS().forEach(({ lib, rpc, setup, protocol }) => { - const Tezos = lib; - const Limanet = protocol === Protocols.PtLimaPtL ? it : it.skip; - - describe(`Test tx rollup origination using: ${rpc}`, () => { - - beforeEach(async (done) => { - await setup(true); - done(); - }); - Limanet('should succeed to originate a rollup with auto-estimate of the fees', async (done) => { - const op = await Tezos.contract.txRollupOriginate(); - await op.confirmation(); - expect(op.hash).toBeDefined(); - expect(op.originatedRollup).toBeDefined(); - expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY); - expect(op.status).toBe('applied'); - - done(); - }); - - Limanet('should succeed to originate a rollup with defined fees', async (done) => { - const op = await Tezos.contract.txRollupOriginate({ - storageLimit: 60000, - gasLimit: 2000, - fee: 500 - }); - await op.confirmation(); - expect(op.hash).toBeDefined(); - expect(op.originatedRollup).toBeDefined(); - expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY); - expect(op.status).toBe('applied'); - - done(); - }); - - Limanet('should succeed to include a rollupOrigination operation in a batch', async (done) => { - const op = await Tezos.contract.batch([ - { kind: OpKind.TRANSACTION, to: 'tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu', amount: 0.02 }, - { kind: OpKind.TX_ROLLUP_ORIGINATION } - ]).send(); - await op.confirmation(); - expect(op.hash).toBeDefined(); - expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY); - expect(op.status).toBe('applied'); - - done(); - }); - - Limanet('should succeed to include a rollupOrigination operation in a batch using `with` method', async (done) => { - const op = await Tezos.contract.batch() - .withTransfer({ to: 'tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu', amount: 0.02 }) - .withTxRollupOrigination() - .send(); - await op.confirmation(); - expect(op.hash).toBeDefined(); - expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY); - expect(op.status).toBe('applied'); - done(); - }); - }); -}); diff --git a/integration-tests/contract-tx-wait-2-confirmations.spec.ts b/integration-tests/contract-tx-wait-2-confirmations.spec.ts deleted file mode 100644 index 19fe3ba054..0000000000 --- a/integration-tests/contract-tx-wait-2-confirmations.spec.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { CONFIGS } from "./config"; - -CONFIGS().forEach(({ lib, rpc, setup }) => { - const Tezos = lib; - describe(`Test tx and waiting for 2 confirmations through contract api using: ${rpc}`, () => { - - beforeEach(async (done) => { - await setup(); - done(); - }); - test('Verify contract.transfer for 2 XTZ to an address and waits for 2 confirmations', async (done) => { - const op = await Tezos.contract.transfer({ to: 'tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu', amount: 2 }); - await op.confirmation(); - expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY); - expect(Number(op.consumedGas)).toBeGreaterThan(0); - const [first, second] = await Promise.all([op.confirmation(), op.confirmation(2)]); - expect(second - first).toEqual(1); - // Retrying another time should be instant - const [first2, second2] = await Promise.all([op.confirmation(), op.confirmation(2)]); - expect(second2 - first2).toEqual(1); - done(); - }); - }); -}); diff --git a/integration-tests/data/allTestsCases.ts b/integration-tests/data/allTestsCases.ts index 221cc2cf95..d32a973521 100644 --- a/integration-tests/data/allTestsCases.ts +++ b/integration-tests/data/allTestsCases.ts @@ -1196,60 +1196,6 @@ export const commonCases: TestCase[] = [ ], }, }, - { - name: `Tx rollup origination`, - operation: { - branch: 'BMV9bffK5yjWCJgUJBsoTRifb4SsAYbkCVwVkKbJHffJYn7ePBL', - contents: [ - { - kind: OpKind.TX_ROLLUP_ORIGINATION, - counter: '1', - source: 'tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn', - fee: '10000', - gas_limit: '10', - storage_limit: '10', - tx_rollup_origination: {}, - }, - ], - }, - }, - { - name: `Tx rollup submit batch`, - operation: { - branch: 'BMV9bffK5yjWCJgUJBsoTRifb4SsAYbkCVwVkKbJHffJYn7ePBL', - contents: [ - { - kind: OpKind.TX_ROLLUP_SUBMIT_BATCH, - counter: '1', - source: 'tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn', - fee: '10000', - gas_limit: '10', - storage_limit: '10', - rollup: 'txr1YTdi9BktRmybwhgkhRK7WPrutEWVGJT7w', - content: 'abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd', - burn_limit: '1000000', - }, - ], - }, - }, - { - name: `Tx rollup submit batch no burn limit`, - operation: { - branch: 'BMV9bffK5yjWCJgUJBsoTRifb4SsAYbkCVwVkKbJHffJYn7ePBL', - contents: [ - { - kind: OpKind.TX_ROLLUP_SUBMIT_BATCH, - counter: '1', - source: 'tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn', - fee: '10000', - gas_limit: '10', - storage_limit: '10', - rollup: 'txr1YTdi9BktRmybwhgkhRK7WPrutEWVGJT7w', - content: '1234', - }, - ], - }, - }, { name: `Origination of a contract that contains the instructions EMIT`, operation: { diff --git a/integration-tests/data/contract_origination.ts b/integration-tests/data/contract_origination.ts index 2fe022430a..41b0931438 100644 --- a/integration-tests/data/contract_origination.ts +++ b/integration-tests/data/contract_origination.ts @@ -1,69 +1,5 @@ import { OperationContentsOrigination } from "@taquito/rpc" -export const contractOriginationParams = { - "code": - [{ - "prim": "parameter", - "args": - [{ - "prim": "pair", - "args": - [{ "prim": "string" }, { "prim": "nat" }, - { "prim": "tx_rollup_l2_address" }, - { "prim": "address" }] - }] - }, - { "prim": "storage", "args": [{ "prim": "unit" }] }, - { - "prim": "code", - "args": - [[{ "prim": "CAR" }, - { - "prim": "UNPAIR", - "args": [{ "int": "4" }] - }, - { "prim": "TICKET" }, { "prim": "PAIR" }, - { "prim": "SWAP" }, - { - "prim": "CONTRACT", - "args": - [{ - "prim": "pair", - "args": - [{ - "prim": "ticket", - "args": [{ "prim": "string" }] - }, - { "prim": "tx_rollup_l2_address" }] - }], - "annots": ["%deposit"] - }, - [{ - "prim": "IF_NONE", - "args": - [[[{ "prim": "UNIT" }, - { "prim": "FAILWITH" }]], []] - }], - { "prim": "SWAP" }, - { - "prim": "PUSH", - "args": - [{ "prim": "mutez" }, { "int": "0" }] - }, - { "prim": "SWAP" }, - { "prim": "TRANSFER_TOKENS" }, - { "prim": "UNIT" }, - { - "prim": "NIL", - "args": [{ "prim": "operation" }] - }, - { "prim": "DIG", "args": [{ "int": "2" }] }, - { "prim": "CONS" }, { "prim": "PAIR" }]] - }], - "storage": { "prim": "Unit" } -} - - export const rpcToForge = { "branch": "BLQ6JyEEzUNkA7WEDSAbyFYLoEK7RVcNcjbjrN5LrmqoUW4qmu3", "contents": diff --git a/integration-tests/data/tickets_deposit_contract.ts b/integration-tests/data/tickets_deposit_contract.ts deleted file mode 100644 index 5e286f5453..0000000000 --- a/integration-tests/data/tickets_deposit_contract.ts +++ /dev/null @@ -1,20 +0,0 @@ -export const ticketsDeposit = `parameter (pair string nat tx_rollup_l2_address address); -storage unit; -code { - CAR; - UNPAIR 4; - TICKET; - PAIR; - SWAP; - CONTRACT %deposit (pair (ticket string) tx_rollup_l2_address); - ASSERT_SOME; - SWAP; - PUSH mutez 0; - SWAP; - TRANSFER_TOKENS; - UNIT; - NIL operation; - DIG 2; - CONS; - PAIR; - };` diff --git a/integration-tests/injecting-multiple-manager-operations-in-a-block.spec.ts b/integration-tests/injecting-multiple-manager-operations-in-a-block.spec.ts index 95441c96d1..1431a31b05 100644 --- a/integration-tests/injecting-multiple-manager-operations-in-a-block.spec.ts +++ b/integration-tests/injecting-multiple-manager-operations-in-a-block.spec.ts @@ -4,7 +4,7 @@ import { CONFIGS } from "./config"; CONFIGS().forEach(({ lib, rpc, setup, protocol }) => { const Tezos = lib; const limanet = (protocol === Protocols.PtLimaPtL) ? test : test.skip; - const alpha = (protocol === Protocols.ProtoALpha) ? test : test.skip; + const mumbaiAndAlpha = protocol === Protocols.PtMumbaii || protocol === Protocols.ProtoALpha ? test : test.skip; describe(`Test injecting more than one manager operation in a block: ${rpc}`, () => { @@ -29,7 +29,7 @@ CONFIGS().forEach(({ lib, rpc, setup, protocol }) => { done(); }) - alpha('Verify that doing transfers without awaiting the confirmation after each will fail', async (done) => { + mumbaiAndAlpha('Verify that doing transfers without awaiting the confirmation after each will fail', async (done) => { try { const op1Promise = Tezos.contract.transfer({ to: 'tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu', amount: 1 }); const op2Promise = Tezos.contract.transfer({ to: 'tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu', amount: 2 }); diff --git a/integration-tests/ledger-signer.spec.ts b/integration-tests/ledger-signer.spec.ts index f7ca0c2ae5..4bb43f71f1 100644 --- a/integration-tests/ledger-signer.spec.ts +++ b/integration-tests/ledger-signer.spec.ts @@ -4,7 +4,7 @@ import TransportNodeHid from "@ledgerhq/hw-transport-node-hid"; import { ligoSample } from "./data/ligo-simple-contract"; import { OriginateParams, TezosToolkit } from '@taquito/taquito'; import { localForger } from '@taquito/local-forging'; -import { contractOriginationParams, rpcToForge } from './data/contract_origination'; +import { rpcToForge } from './data/contract_origination'; import { MichelsonV1Expression } from '@taquito/rpc'; // PLEASE NOTE MAY NEED TO TEST ONE TEST AT A TIME diff --git a/integration-tests/originate-known-contracts.ts b/integration-tests/originate-known-contracts.ts index 2489b87829..03e0c9571e 100644 --- a/integration-tests/originate-known-contracts.ts +++ b/integration-tests/originate-known-contracts.ts @@ -1,5 +1,5 @@ import { CONFIGS } from './config'; -import { MichelsonMap, OriginateParams, Protocols, RpcForger, TezosToolkit } from '@taquito/taquito'; +import { MichelsonMap, OriginateParams, RpcForger, TezosToolkit } from '@taquito/taquito'; import { singleSaplingStateContractJProtocol } from './data/single_sapling_state_contract_jakarta_michelson'; import { fa2ForTokenMetadataView } from './data/fa2-for-token-metadata-view'; import { char2Bytes } from '@taquito/utils'; @@ -134,28 +134,6 @@ CONFIGS().forEach(({ lib, setup, protocol }) => { storage: 2 }); - // originate tx rollup - if (protocol === Protocols.ProtoALpha) { - fs.appendFile(`known-contracts-${protocol.substring(0,9)}.ts`, `export const txRollupAddress${protocol.substring(0,9)} = "";\n`, (err: any) => { - if (err) { - console.error(err); - } - }); - } else { - try { - const op = await tezos.contract.txRollupOriginate({}); - await op.confirmation(); - console.log(`txRollupAddress: ${op.originatedRollup}`); - fs.appendFile(`known-contracts-${protocol.substring(0,9)}.ts`, `export const txRollupAddress${protocol.substring(0,9)} = "${op.originatedRollup}";\n`, (err: any) => { - if (err) { - console.error(err); - } - }); - } catch (e: any) { - console.error(`Failed to originate tx rollup | Error: ${e.stack}`); - } - } - console.log(` ################################################################################ Public Key Hash : ${keyPkh} diff --git a/integration-tests/prepare-operation.spec.ts b/integration-tests/prepare-operation.spec.ts index 9575e64445..41e65b3bd1 100644 --- a/integration-tests/prepare-operation.spec.ts +++ b/integration-tests/prepare-operation.spec.ts @@ -86,19 +86,6 @@ CONFIGS().forEach(({ lib, setup, protocol }) => { done(); }); - limanet('should be able to prepare a txRollupOriginate operation', async (done) => { - const prepared = await Tezos.prepare.txRollupOrigination({}); - - expect(prepared).toBeDefined(); - expect(prepared.counter).toBeDefined(); - expect(prepared.opOb).toBeDefined(); - expect(prepared.opOb.branch).toBeDefined(); - expect(prepared.opOb.contents).toBeDefined(); - expect(prepared.opOb.contents[0].kind).toEqual('tx_rollup_origination'); - - done(); - }); - it('should be able to prepare a ballot operation', async (done) => { const prepared = await Tezos.prepare.ballot({ proposal: 'PtKathmankSpLLDALzWw7CGD2j2MtyveTwboEYokqUCP4a1LxMg', diff --git a/integration-tests/rpc-nodes.spec.ts b/integration-tests/rpc-nodes.spec.ts index 35e05610fb..68e53e848c 100644 --- a/integration-tests/rpc-nodes.spec.ts +++ b/integration-tests/rpc-nodes.spec.ts @@ -1,9 +1,10 @@ import { CONFIGS } from './config'; -import { Protocols } from "@taquito/taquito"; +import { DefaultContractType, Protocols } from "@taquito/taquito"; import { RpcClientCache, RpcClient, RPCRunViewParam, RPCRunScriptViewParam } from '@taquito/rpc'; import { encodeExpr } from '@taquito/utils'; import { Schema } from '@taquito/michelson-encoder'; import { tokenBigmapCode, tokenBigmapStorage } from './data/token_bigmap'; +import { ticketCode, ticketStorage } from './data/code_with_ticket'; CONFIGS().forEach( ({ @@ -16,16 +17,32 @@ CONFIGS().forEach( knownBigMapContract, knownSaplingContract, knownViewContract, - txRollupAddress, }) => { const Tezos = lib; - const Limanet = protocol === Protocols.PtLimaPtL ? it : it.skip; - + const mumbaiAndAlpha = protocol === Protocols.PtMumbaii || protocol === Protocols.ProtoALpha ? test : test.skip; const unrestrictedRPCNode = rpc.endsWith("ecadinfra.com") ? test.skip : test; + let ticketContract: DefaultContractType; + beforeAll(async (done) => { await setup(); + + try { + // originate ticket contract + const ticketOp = await Tezos.contract.originate({ + code: ticketCode, + storage: ticketStorage, + }); + await ticketOp.confirmation(); + ticketContract = await ticketOp.contract(); + // contract call to issue tickets + const ticketCallOp = await ticketContract.methods.auto_call(1).send(); + await ticketCallOp.confirmation(); + } catch (e) { + console.log(JSON.stringify(e)); + } + done(); }); @@ -410,18 +427,6 @@ CONFIGS().forEach( done(); }); - Limanet('Verify that rpcClient.getTxRollupInbox will access the inbox of a transaction rollup on lima', async (done) => { - const inbox = await rpcClient.getTxRollupInbox(txRollupAddress, '0'); - expect(inbox).toBeDefined(); - done(); - }); - - Limanet('Verify that rpcClient.getTxRollupState will access the state of a rollup on lima', async (done) => { - const state = await rpcClient.getTxRollupState(txRollupAddress); - expect(state).toBeDefined(); - done(); - }); - it('Verify that rpcClient.getStorageUsedSpace will retrieve the used space of a contract storage', async (done) => { const usedSpace = await rpcClient.getStorageUsedSpace(knownContract); expect(usedSpace).toBeDefined(); @@ -433,6 +438,22 @@ CONFIGS().forEach( expect(paidSpace).toBeDefined(); done(); }); + + mumbaiAndAlpha('Verify that rpcClient.ticketBalance will retrieve the specified ticket owned by the given contract', async (done) => { + const ticketBalance = await rpcClient.getTicketBalance(ticketContract.address, { ticketer: ticketContract.address, content_type: { prim: 'string' }, content: { string: 'abc' } } ); + expect(ticketBalance).toBeDefined(); + done(); + }); + + mumbaiAndAlpha('Verify that rpcClient.allTicketBalances will retrieve all tickets owned by the given contract', async (done) => { + const ticketBalances = await rpcClient.getAllTicketBalances(ticketContract.address); + expect(ticketBalances).toBeInstanceOf(Array) + expect(ticketBalances[0].ticketer).toBe(ticketContract.address) + expect(ticketBalances[0].content_type).toBeDefined() + expect(ticketBalances[0].content).toBeDefined() + expect(ticketBalances[0].amount).toBeDefined() + done(); + }); }); }); } diff --git a/integration-tests/sandbox-env.sh b/integration-tests/sandbox-env.sh index 05cb4ba4a9..4af895bc9a 100755 --- a/integration-tests/sandbox-env.sh +++ b/integration-tests/sandbox-env.sh @@ -1,7 +1,7 @@ #!/bin/sh -export RUN_LIMANET_WITH_SECRET_KEY=true +export RUN_MUMBAINET_WITH_SECRET_KEY=true export SECRET_KEY=edsk3RFgDiCt7tWB2oe96w1eRw72iYiiqZPLu9nnEY23MYRp2d8Kkx -export TEZOS_RPC_LIMANET=http://localhost:20000 +export TEZOS_RPC_MUMBAINET=http://localhost:20000 export POLLING_INTERVAL_MILLISECONDS=100 export RPC_CACHE_MILLISECONDS=0 export TEZOS_BAKER=tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb diff --git a/integration-tests/tx-rollup-l2-address.spec.ts b/integration-tests/tx-rollup-l2-address.spec.ts deleted file mode 100644 index 5cac337aba..0000000000 --- a/integration-tests/tx-rollup-l2-address.spec.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { CONFIGS } from "./config"; -import { UnitValue } from '@taquito/michelson-encoder'; -import { Protocols } from "@taquito/taquito"; - -CONFIGS().forEach(({ lib, setup, protocol, txRollupAddress, rpc }) => { - const tezos = lib; - const Limanet = protocol === Protocols.PtLimaPtL ? test : test.skip; - - describe(`Contract originations and method calls to test the type of tx_rollup_l2_address: ${rpc}`, () => { - beforeEach(async (done) => { - await setup(); - done(); - }); - - Limanet(`Originate a contract with a hex string type tz1 & tz4 in initial storage tz4 & string`, async (done) => { - const op = await tezos.contract.originate({ - code: ` - parameter (pair address tx_rollup_l2_address string); - storage (unit); - code { - # cast the address to contract type - CAR; - UNPAIR; - CONTRACT %deposit (pair (ticket (pair unit string)) tx_rollup_l2_address); - - IF_SOME { - SWAP; - UNPAIR; SWAP; - - # create a ticket - PUSH nat 10; - SWAP; - UNIT; - PAIR; - TICKET; - ASSERT_SOME; - PAIR; - - # amount for transfering - PUSH mutez 0; - SWAP; - - # deposit - TRANSFER_TOKENS; - - DIP { NIL operation }; - CONS; - - DIP { PUSH unit Unit }; - PAIR; - } - { FAIL ; } - } - `, - storage: "Unit" - }); - await op.confirmation(); - expect(op.hash).toBeDefined(); - expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY); - - const contract = await op.contract(); - - const storage = await contract.storage(); - expect(JSON.stringify(storage)).toEqual(JSON.stringify(UnitValue)); - - const ticketDeposit = await contract.methods.default(txRollupAddress, 'tz4VHgLiRx5ZZjwU2QaybHc11EMJk3NcyvVc', '1').send(); - await ticketDeposit.confirmation(); - - expect(ticketDeposit.hash).toBeDefined(); - expect(ticketDeposit.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY); - expect(JSON.stringify(await contract.storage())).toEqual(JSON.stringify(UnitValue)); - done(); - }); - - Limanet(`Contract with params and storage as tx_rollup_l2_address`, async (done) => { - const op = await tezos.contract.originate({ - code: [{ "prim": "parameter", "args": [{ "prim": "tx_rollup_l2_address" }] }, { "prim": "storage", "args": [{ "prim": "tx_rollup_l2_address" }] }, { "prim": "code", "args": [[{ "prim": "CAR" }, { "prim": "NIL", "args": [{ "prim": "operation" }] }, { "prim": "PAIR" }]] }], - storage: "tz4QyWfEiv56CVDATV3DT3CDVhPaMKif2Ce8" - }); - await op.confirmation(); - - expect(op.hash).toBeDefined(); - expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY); - - const contract = await op.contract(); - const pkh = await contract.storage(); - expect(pkh).toEqual("tz4QyWfEiv56CVDATV3DT3CDVhPaMKif2Ce8"); - - const ticketDeposit = await contract.methods.default(pkh).send(); - await ticketDeposit.confirmation(); - expect(ticketDeposit.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY); - done(); - }); - }); -}); diff --git a/packages/taquito-contracts-library/src/rpc-wrapper.ts b/packages/taquito-contracts-library/src/rpc-wrapper.ts index fa2a7ff411..67feab1133 100644 --- a/packages/taquito-contracts-library/src/rpc-wrapper.ts +++ b/packages/taquito-contracts-library/src/rpc-wrapper.ts @@ -44,6 +44,8 @@ import { UnparsingMode, VotesListingsResponse, VotingPeriodBlockResult, + TicketTokenParams, + AllTicketBalances, } from '@taquito/rpc'; import { ContractsLibrary } from './taquito-contracts-library'; @@ -306,4 +308,17 @@ export class RpcWrapperContractsLibrary implements RpcClientInterface { ): Promise { return this.rpc.getStoragePaidSpace(contract, { block }); } + async getTicketBalance( + contract: string, + ticket: TicketTokenParams, + { block }: RPCOptions = defaultRPCOptions + ): Promise { + return this.rpc.getTicketBalance(contract, ticket, { block }); + } + async getAllTicketBalances( + contract: string, + { block }: RPCOptions = defaultRPCOptions + ): Promise { + return this.rpc.getAllTicketBalances(contract, { block }); + } } diff --git a/packages/taquito-rpc/src/rpc-client-interface.ts b/packages/taquito-rpc/src/rpc-client-interface.ts index 03efa80fe0..06f32c862f 100644 --- a/packages/taquito-rpc/src/rpc-client-interface.ts +++ b/packages/taquito-rpc/src/rpc-client-interface.ts @@ -44,6 +44,8 @@ import { VotesListingsResponse, VotingInfoResponse, VotingPeriodBlockResult, + TicketTokenParams, + AllTicketBalances, } from './types'; export interface RPCOptions { @@ -119,6 +121,12 @@ export interface RpcClientInterface { ): Promise; getStorageUsedSpace(contract: string, options?: RPCOptions): Promise; getStoragePaidSpace(contract: string, options?: RPCOptions): Promise; + getTicketBalance( + contract: string, + ticket: TicketTokenParams, + options?: RPCOptions + ): Promise; + getAllTicketBalances(contract: string, options?: RPCOptions): Promise; } export enum RPCMethodName { @@ -159,4 +167,6 @@ export enum RPCMethodName { PACK_DATA = 'packData', GET_STORAGE_USED_SPACE = 'getStorageUsedSpace', GET_STORAGE_PAID_SPACE = 'getStoragePaidSpace', + GET_TICKET_BALANCE = 'getTicketBalance', + GET_ALL_TICKET_BALANCES = 'getAllTicketBalances', } 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 964051c7d7..a53f276add 100644 --- a/packages/taquito-rpc/src/rpc-client-modules/rpc-cache.ts +++ b/packages/taquito-rpc/src/rpc-client-modules/rpc-cache.ts @@ -46,6 +46,8 @@ import { UnparsingMode, VotesListingsResponse, VotingPeriodBlockResult, + TicketTokenParams, + AllTicketBalances, } from '../types'; import { @@ -68,7 +70,6 @@ type RpcMethodParam = | UnparsingMode | BigMapKey | BakingRightsQueryArguments - | PackDataParams | EndorsingRightsQueryArguments; const defaultTtl = 1000; @@ -114,7 +115,7 @@ export class RpcClientCache implements RpcClientInterface { : paramsToString + param + '/'; }); return rpcMethodData - ? `${rpcUrl}/${rpcMethodName}/${paramsToString}/${JSON.stringify(rpcMethodData)}` + ? `${rpcUrl}/${rpcMethodName}/${paramsToString}${JSON.stringify(rpcMethodData)}/` : `${rpcUrl}/${rpcMethodName}/${paramsToString}`; } @@ -292,7 +293,8 @@ export class RpcClientCache implements RpcClientInterface { const key = this.formatCacheKey( this.rpcClient.getRpcUrl(), RPCMethodName.GET_NORMALIZED_SCRIPT, - [block, address, unparsingMode] + [block, address], + unparsingMode ); if (this.has(key)) { return this.get(key); @@ -401,11 +403,12 @@ export class RpcClientCache implements RpcClientInterface { { block }: { block: string } = defaultRPCOptions ): Promise { this.validateAddress(address); - const keyUrl = this.formatCacheKey(this.rpcClient.getRpcUrl(), RPCMethodName.GET_BIG_MAP_KEY, [ - block, - address, - key, - ]); + const keyUrl = this.formatCacheKey( + this.rpcClient.getRpcUrl(), + RPCMethodName.GET_BIG_MAP_KEY, + [block, address], + key + ); if (this.has(keyUrl)) { return this.get(keyUrl); } else { @@ -936,10 +939,12 @@ export class RpcClientCache implements RpcClientInterface { data: PackDataParams, { block }: RPCOptions = defaultRPCOptions ): Promise<{ packed: string; gas: BigNumber | 'unaccounted' | undefined }> { - const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), RPCMethodName.PACK_DATA, [ - block, - data, - ]); + const key = this.formatCacheKey( + this.rpcClient.getRpcUrl(), + RPCMethodName.PACK_DATA, + [block], + data + ); if (this.has(key)) { return this.get(key); } else { @@ -1165,4 +1170,58 @@ export class RpcClientCache implements RpcClientInterface { return response; } } + + /** + * + * @param contract address of the contract we want to retrieve ticket balance of + * @param ticket Ticket token parameter object that contains ticketer, content type, and content + * @param options contains generic configuration for rpc calls + * @description Access the contract's balance of ticket with specified ticketer, content type, and content. + * @example ticket{ ticketer: 'address', content_type: { prim: "string" }, content: { string: 'ticket1' } } + * @see https://tezos.gitlab.io/protocols/016_mumbai.html#rpc-changes + */ + async getTicketBalance( + contract: string, + ticket: TicketTokenParams, + { block }: RPCOptions = defaultRPCOptions + ): Promise { + const key = this.formatCacheKey( + this.rpcClient.getRpcUrl(), + RPCMethodName.GET_TICKET_BALANCE, + [block, contract], + ticket + ); + if (this.has(key)) { + return this.get(key); + } else { + const response = this.rpcClient.getTicketBalance(contract, ticket, { block }); + this.put(key, response); + return response; + } + } + + /** + * + * @param contract address of the contract to retrieve all ticket balances from + * @param options contains generic configuration for rpc calls + * @description Access the complete list of tickets owned by the given contract by scanning the contract's storage. + * @see https://tezos.gitlab.io/protocols/016_mumbai.html#rpc-changes + */ + async getAllTicketBalances( + contract: string, + { block }: RPCOptions = defaultRPCOptions + ): Promise { + const key = this.formatCacheKey( + this.rpcClient.getRpcUrl(), + RPCMethodName.GET_ALL_TICKET_BALANCES, + [block, contract] + ); + if (this.has(key)) { + return this.get(key); + } else { + const response = this.rpcClient.getAllTicketBalances(contract, { block }); + this.put(key, response); + return response; + } + } } diff --git a/packages/taquito-rpc/src/taquito-rpc.ts b/packages/taquito-rpc/src/taquito-rpc.ts index 7c697ab764..7aa70871b6 100644 --- a/packages/taquito-rpc/src/taquito-rpc.ts +++ b/packages/taquito-rpc/src/taquito-rpc.ts @@ -57,6 +57,8 @@ import { VotingPeriodBlockResult, TxRollupStateResponse, TxRollupInboxResponse, + TicketTokenParams, + AllTicketBalances, } from './types'; import { castToBigNumber } from './utils/utils'; import { @@ -1126,4 +1128,48 @@ export class RpcClient implements RpcClientInterface { method: 'GET', }); } + + /** + * + * @param contract implicit or originated address we want to retrieve ticket balance of + * @param ticket object to specify a ticket by ticketer, content type and content + * @param options contains generic configuration for rpc calls + * @description Access the contract's balance of ticket with specified ticketer, content type, and content. + * @example ticket { ticketer: 'address', content_type: { prim: "string" }, content: { string: 'ticket1' } } + * @see https://tezos.gitlab.io/protocols/016_mumbai.html#rpc-changes + */ + async getTicketBalance( + contract: string, + ticket: TicketTokenParams, + { block }: { block: string } = defaultRPCOptions + ): Promise { + return this.httpBackend.createRequest( + { + url: this.createURL( + `/chains/${this.chain}/blocks/${block}/context/contracts/${contract}/ticket_balance` + ), + method: 'POST', + }, + ticket + ); + } + + /** + * + * @param contract originated address we want to retrieve ticket balances of + * @param options contains generic configuration for rpc calls + * @description Access the complete list of tickets owned by the given contract by scanning the contract's storage. + * @see https://tezos.gitlab.io/protocols/016_mumbai.html#rpc-changes + */ + async getAllTicketBalances( + contract: string, + { block }: { block: string } = defaultRPCOptions + ): Promise { + return this.httpBackend.createRequest({ + url: this.createURL( + `/chains/${this.chain}/blocks/${block}/context/contracts/${contract}/all_ticket_balances` + ), + method: 'GET', + }); + } } diff --git a/packages/taquito-rpc/src/types.ts b/packages/taquito-rpc/src/types.ts index f903f5dad5..fb3f2e2ea3 100644 --- a/packages/taquito-rpc/src/types.ts +++ b/packages/taquito-rpc/src/types.ts @@ -1148,6 +1148,21 @@ export interface PackDataParams { gas?: BigNumber; } +export interface TicketTokenParams { + ticketer: string; + content_type: MichelsonV1Expression; + content: MichelsonV1Expression; +} + +export interface TicketBalance { + ticketer: string; + content_type: MichelsonV1Expression; + content: MichelsonV1Expression; + amount: string; +} + +export type AllTicketBalances = TicketBalance[]; + export type HexString = string; export interface PackDataResponse { diff --git a/packages/taquito-rpc/test/data/rpc-responses.ts b/packages/taquito-rpc/test/data/rpc-responses.ts index f118596b10..bcecb8f2bb 100644 --- a/packages/taquito-rpc/test/data/rpc-responses.ts +++ b/packages/taquito-rpc/test/data/rpc-responses.ts @@ -5391,6 +5391,19 @@ export const txRollupInbox = { merkle_root: 'txi3Ef5CSsBWRaqQhWj2zg51J3tUqHFD47na6ex7zcboTG5oXEFrm', }; +export const ticketBalancesResponse = [ + { + ticketer: 'KT1X6mCNdfQZSpyU9zZw9sWckPVJyz2X8vwD', + content_type: { + prim: 'string', + }, + content: { + string: 'ticket1', + }, + amount: '1', + }, +]; + export const ticketUpdatesSample = { protocol: 'PtLimaPtLMwfNinJi9rCfDPWea8dFgTZ1MeJ9f1m2SRic6ayiwW', chain_id: 'NetXizpkH94bocH', diff --git a/packages/taquito-rpc/test/rpc-cache.spec.ts b/packages/taquito-rpc/test/rpc-cache.spec.ts index 4199cbf08e..dc9be3f9c7 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, txRollupInbox, txRollupState, + ticketBalancesResponse, } from './data/rpc-responses'; /** @@ -45,6 +46,11 @@ describe('RpcClientCache test', () => { const contractAddress = 'KT1Fe71jyjrxFg9ZrYqtvaX7uQjcLo7svE4D'; const txRollupId = 'txr1YTdi9BktRmybwhgkhRK7WPrutEWVGJT7w'; const blockLevel = '0'; + const ticketToken = { + ticketer: contractAddress, + content_type: { prim: 'string' }, + content: { string: 'ticket1' }, + }; beforeEach(() => { mockRpcClient = { @@ -84,6 +90,8 @@ describe('RpcClientCache test', () => { getProtocols: jest.fn(), getTxRollupInbox: jest.fn(), getTxRollupState: jest.fn(), + getTicketBalance: jest.fn(), + getAllTicketBalances: jest.fn(), }; mockRpcClient.getRpcUrl.mockReturnValue(rpcUrl); @@ -121,6 +129,8 @@ describe('RpcClientCache test', () => { mockRpcClient.getProtocols.mockReturnValue(protocols); mockRpcClient.getTxRollupInbox.mockReturnValue(txRollupInbox); mockRpcClient.getTxRollupState.mockReturnValue(txRollupState); + mockRpcClient.getTicketBalance.mockReturnValue('3'); + mockRpcClient.getAllTicketBalances.mockReturnValue(ticketBalancesResponse); rpcCache = new RpcClientCache(mockRpcClient); }); @@ -167,6 +177,12 @@ describe('RpcClientCache test', () => { await rpcCache.getProtocols(); await rpcCache.getTxRollupInbox(txRollupId, blockLevel); await rpcCache.getTxRollupState(txRollupId); + await rpcCache.getTicketBalance(contractAddress, { + ticketer: contractAddress, + content_type: { prim: 'string' }, + content: { string: 'ticket1' }, + }); + await rpcCache.getAllTicketBalances(contractAddress); expect(rpcCache.getAllCachedData()['rpcTest/getBlockHash/head/'].response).toEqual(blockHash); expect(rpcCache.getAllCachedData()['rpcTest/getBlock/head/'].response).toEqual(blockResponse); @@ -255,6 +271,14 @@ describe('RpcClientCache test', () => { expect( rpcCache.getAllCachedData()[`rpcTest/getTxRollupState/head/${txRollupId}/`].response ).toEqual(txRollupState); + expect( + rpcCache.getAllCachedData()[ + `rpcTest/getTicketBalance/head/${contractAddress}/${JSON.stringify(ticketToken)}/` + ].response + ).toEqual('3'); + expect( + rpcCache.getAllCachedData()[`rpcTest/getAllTicketBalances/head/${contractAddress}/`].response + ).toEqual(ticketBalancesResponse); rpcCache.deleteAllCachedData(); done(); @@ -303,6 +327,16 @@ describe('RpcClientCache test', () => { await rpcCache.getProtocols(block); await rpcCache.getTxRollupInbox(txRollupId, blockLevel, block); await rpcCache.getTxRollupState(txRollupId, block); + await rpcCache.getTicketBalance( + contractAddress, + { + ticketer: contractAddress, + content_type: { prim: 'string' }, + content: { string: 'ticket1' }, + }, + block + ); + await rpcCache.getAllTicketBalances(contractAddress, block); expect(rpcCache.getAllCachedData()[`rpcTest/getBlockHash/${block.block}/`].response).toEqual( blockHash @@ -408,10 +442,18 @@ describe('RpcClientCache test', () => { `rpcTest/getTxRollupInbox/${block.block}/${txRollupId}/${blockLevel}/` ].response ).toEqual(txRollupInbox); - expect( rpcCache.getAllCachedData()[`rpcTest/getTxRollupState/${block.block}/${txRollupId}/`].response ).toEqual(txRollupState); + expect( + rpcCache.getAllCachedData()[ + `rpcTest/getTicketBalance/${block.block}/${contractAddress}/${JSON.stringify(ticketToken)}/` + ].response + ).toEqual('3'); + expect( + rpcCache.getAllCachedData()[`rpcTest/getAllTicketBalances/${block.block}/${contractAddress}/`] + .response + ).toEqual(ticketBalancesResponse); rpcCache.deleteAllCachedData(); done(); @@ -453,6 +495,8 @@ describe('RpcClientCache test', () => { await rpcCache.getCurrentPeriod(); await rpcCache.getSuccessorPeriod(); await rpcCache.getProtocols(); + await rpcCache.getTicketBalance(contractAddress, ticketToken); + await rpcCache.getAllTicketBalances(contractAddress); rpcCache.deleteAllCachedData(); diff --git a/packages/taquito-rpc/test/taquito-rpc.spec.ts b/packages/taquito-rpc/test/taquito-rpc.spec.ts index 13d6bcbddf..c3b775b8e3 100644 --- a/packages/taquito-rpc/test/taquito-rpc.spec.ts +++ b/packages/taquito-rpc/test/taquito-rpc.spec.ts @@ -50,6 +50,7 @@ import { delegatesKathmandunetSample, votingInfoKathmandunetSample, ticketUpdatesSample, + ticketBalancesResponse, smartRollupOriginateResponse, smartRollupAddMessagesResponse, smartRollupExecuteOutboxMessageResponse, @@ -4377,4 +4378,38 @@ describe('RpcClient test', () => { done(); }); }); + + describe('ticketBalance', () => { + it('should query the right url and data', async (done) => { + httpBackend.createRequest.mockResolvedValue('3'); + const response = await client.getTicketBalance(contractAddress, { + ticketer: contractAddress, + content_type: { prim: 'string ' }, + content: { string: 'ticket1' }, + }); + + expect(httpBackend.createRequest.mock.calls[0][0]).toEqual({ + method: 'POST', + url: `root/chains/test/blocks/head/context/contracts/${contractAddress}/ticket_balance`, + }); + + expect(response).toEqual('3'); + done(); + }); + }); + + describe('ticketAllBalance', () => { + it('should query the right url and data', async (done) => { + httpBackend.createRequest.mockResolvedValue(ticketBalancesResponse); + const response = await client.getAllTicketBalances('KT1X6mCNdfQZSpyU9zZw9sWckPVJyz2X8vwD'); + + expect(httpBackend.createRequest.mock.calls[0][0]).toEqual({ + method: 'GET', + url: `root/chains/test/blocks/head/context/contracts/KT1X6mCNdfQZSpyU9zZw9sWckPVJyz2X8vwD/all_ticket_balances`, + }); + + expect(response).toEqual(ticketBalancesResponse); + done(); + }); + }); });