From ecade81b5a4af4699f2b7e8c74d879f10c13eb50 Mon Sep 17 00:00:00 2001 From: hui-an-yang <106410553+hui-an-yang@users.noreply.github.com> Date: Thu, 17 Nov 2022 14:49:27 -0800 Subject: [PATCH] 2066 support types for new operations in lima (#2097) * feat: support new types for new operations UpdateConsensusKey and DrainDelegate in Lima re #2066 * test: update_consensus_key unit test added for limanet re #2066 * test: added drain_deleagte unit test for limanet re #2066 * test: minor fix rpc-response data and updateConsensusKey unit test re #2066 * test: addressed comments to update correct test title re #2066 --- packages/taquito-rpc/src/opkind.ts | 2 + packages/taquito-rpc/src/types.ts | 58 +++++ .../taquito-rpc/test/data/rpc-responses.ts | 211 ++++++++++++++++++ packages/taquito-rpc/test/taquito-rpc.spec.ts | 83 +++++++ 4 files changed, 354 insertions(+) diff --git a/packages/taquito-rpc/src/opkind.ts b/packages/taquito-rpc/src/opkind.ts index 9fb1316e20..68a1d8b45c 100644 --- a/packages/taquito-rpc/src/opkind.ts +++ b/packages/taquito-rpc/src/opkind.ts @@ -26,6 +26,8 @@ export enum OpKind { TX_ROLLUP_DISPATCH_TICKETS = 'tx_rollup_dispatch_tickets', TRANSFER_TICKET = 'transfer_ticket', INCREASE_PAID_STORAGE = 'increase_paid_storage', + UPDATE_CONSENSUS_KEY = 'update_consensus_key', + DRAIN_DELEGATE = 'drain_delegate', VDF_REVELATION = 'vdf_revelation', EVENT = 'event', } diff --git a/packages/taquito-rpc/src/types.ts b/packages/taquito-rpc/src/types.ts index da4e77f248..060d5f18ea 100644 --- a/packages/taquito-rpc/src/types.ts +++ b/packages/taquito-rpc/src/types.ts @@ -445,6 +445,23 @@ export interface OperationContentsTransferTicket { entrypoint: string; } +export interface OperationContentsUpdateConsensusKey { + kind: OpKind.UPDATE_CONSENSUS_KEY; + source: string; + fee: string; + counter: string; + gas_limit: string; + storage_limit: string; + pk: string; +} + +export interface OperationContentsDrainDelegate { + kind: OpKind.DRAIN_DELEGATE; + consensus_key: string; + delegate: string; + destination: string; +} + export interface OperationContentsIncreasePaidStorage { kind: OpKind.INCREASE_PAID_STORAGE; source: string; @@ -483,6 +500,8 @@ export type OperationContents = | OperationContentsTxRollupRemoveCommitment | OperationContentsTxRollupRejection | OperationContentsTransferTicket + | OperationContentsUpdateConsensusKey + | OperationContentsDrainDelegate | OperationContentsIncreasePaidStorage; export interface OperationContentsAndResultMetadataExtended { @@ -592,6 +611,17 @@ export interface OperationContentsAndResultMetadataIncreasePaidStorage { internal_operation_results?: InternalOperationResult[]; } +export interface OperationContentsAndResultMetadataUpdateConsensusKey { + balance_updates?: OperationMetadataBalanceUpdates[]; + operation_result: OperationResultUpdateConsensusKey; + internal_operation_results?: InternalOperationResult[]; +} + +export interface OperationContentsAndResultMetadataDrainDelegate { + balance_updates?: OperationMetadataBalanceUpdates[]; + allocated_destination_contract?: boolean; +} + export interface OperationContentsAndResultEndorsement { kind: OpKind.ENDORSEMENT; block_payload_hash?: string; @@ -845,6 +875,25 @@ export interface OperationContentsAndResultTxRollupDispatchTickets { metadata: OperationContentsAndResultMetadataTxRollupDispatchTickets; } +export interface OperationContentsAndResultUpdateConsensusKey { + kind: OpKind.UPDATE_CONSENSUS_KEY; + source: string; + fee: string; + counter: string; + gas_limit: string; + storage_limit: string; + pk: string; + metadata: OperationContentsAndResultMetadataUpdateConsensusKey; +} + +export interface OperationContentsAndResultDrainDelegate { + kind: OpKind.DRAIN_DELEGATE; + consensus_key: string; + delegate: string; + destination: string; + metadata: OperationContentsAndResultMetadataDrainDelegate; +} + export interface OperationContentsAndResultIncreasePaidStorage { kind: OpKind.INCREASE_PAID_STORAGE; source: string; @@ -890,6 +939,8 @@ export type OperationContentsAndResult = | OperationContentsAndResultTxRollupRejection | OperationContentsAndResultTransferTicket | OperationContentsAndResultIncreasePaidStorage + | OperationContentsAndResultUpdateConsensusKey + | OperationContentsAndResultDrainDelegate | OperationContentsAndResultVdfRevelation; export enum OPERATION_METADATA { @@ -1230,6 +1281,13 @@ export interface OperationResultIncreasePaidStorage { errors?: TezosGenericOperationError[]; } +export interface OperationResultUpdateConsensusKey { + status: OperationResultStatusEnum; + consumed_gas?: string; + consumed_milligas?: string; + errors?: TezosGenericOperationError[]; +} + export interface OperationResultDelegation { status: OperationResultStatusEnum; consumed_gas?: string; diff --git a/packages/taquito-rpc/test/data/rpc-responses.ts b/packages/taquito-rpc/test/data/rpc-responses.ts index 39fad86ef4..ac17b5314f 100644 --- a/packages/taquito-rpc/test/data/rpc-responses.ts +++ b/packages/taquito-rpc/test/data/rpc-responses.ts @@ -4833,6 +4833,217 @@ export const blockKathmandunetSample = { ], }; +export const blockLimanetSample = { + protocol: 'PtLimaPtLMwfNinJi9rCfDPWea8dFgTZ1MeJ9f1m2SRic6ayiwW', + chain_id: 'NetXizpkH94bocH', + hash: 'BM5sGpbt1rEiNmfbbo8jcQHJaUZQYwKUXe4MK6B8hcxHDeEfuJx', + header: { + level: 104428, + proto: 2, + predecessor: 'BLoSHvgQ6i64fxa2cWV2PW77FB2apjFpuMgGT9CN9YTCkLHYUEu', + timestamp: '2022-11-02T02:02:55Z', + validation_pass: 4, + operations_hash: 'LLob51uyaK2Kn61U7LPTwPDGe7bEsAifAGjHaAXb5QvfwWv1nBwCC', + fitness: ['02', '000197ec', '', 'ffffffff', '00000000'], + context: 'CoVH2RtM1HHzLZmdbM86EkfwLEg42hmcdr4UGVmUezUDjyUEqYyj', + payload_hash: 'vh2keAERJ5aCT7EagCysfCYcxshQiDKmX1nVPw5mMxB1C6QVZ4eP', + payload_round: 0, + proof_of_work_nonce: 'e45ea3f000000000', + liquidity_baking_toggle_vote: 'off', + signature: + 'sigPXDyg4aUDxaCQKFvsX1Bttek8M9LxSinKCfNnoFEKYBKRL2V7of9vRJUPVckdaA8GYaTcW5W3MXpvASNQX4PeHEkMSrM3', + }, + metadata: { + protocol: 'PtLimaPtLMwfNinJi9rCfDPWea8dFgTZ1MeJ9f1m2SRic6ayiwW', + next_protocol: 'PtLimaPtLMwfNinJi9rCfDPWea8dFgTZ1MeJ9f1m2SRic6ayiwW', + test_chain_status: { status: 'not_running' }, + max_operations_ttl: 120, + max_operation_data_length: 32768, + max_block_header_length: 289, + max_operation_list_length: [ + { max_size: 4194304, max_op: 2048 }, + { max_size: 32768 }, + { max_size: 135168, max_op: 132 }, + { max_size: 524288 }, + ], + proposer: 'tz1PirbogVqfmBT9XCuYJ1KnDx4bnMSYfGru', + baker: 'tz1PirbogVqfmBT9XCuYJ1KnDx4bnMSYfGru', + level_info: { + level: 104428, + level_position: 104427, + cycle: 25, + cycle_position: 2027, + expected_commitment: false, + }, + voting_period_info: { voting_period: { index: 5, kind: 'proposal', start_position: 102400 }, position: 2027, remaining: 2068 }, + nonce_hash: null, + deactivated: [], + balance_updates: [ + { + kind: 'minted', + category: 'baking rewards', + change: '-5000000', + origin: 'block', + }, + { + kind: 'contract', + contract: 'tz1MeT8NACB8Q4uV9dPQ3YxXBmYgapbxQxQ5', + change: '5000000', + origin: 'block', + }, + { + kind: 'minted', + category: 'baking bonuses', + change: '-4073843', + origin: 'block', + }, + { + kind: 'contract', + contract: 'tz1MeT8NACB8Q4uV9dPQ3YxXBmYgapbxQxQ5', + change: '4073843', + origin: 'block', + }, + ], + liquidity_baking_toggle_ema: 583905253, + implicit_operations_results: [ + { + kind: 'transaction', + storage: [ + { int: '1' }, + { int: '261067500100' }, + { int: '100' }, + { bytes: '01e927f00ef734dfc85919635e9afc9166c83ef9fc00' }, + { bytes: '0115eb0104481a6d7921160bc982c5e0a561cd8a3a00' }, + ], + balance_updates: [ + { + kind: 'minted', + category: 'subsidy', + change: '-2500000', + origin: 'subsidy', + }, + { + kind: 'contract', + contract: 'KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5', + change: '2500000', + origin: 'subsidy', + }, + ], + consumed_gas: '225', + consumed_milligas: '224023', + storage_size: '4632', + }, + ], + proposer_consensus_key: 'tz1PirbogVqfmBT9XCuYJ1KnDx4bnMSYfGru', + baker_consensus_key: 'tz1PirbogVqfmBT9XCuYJ1KnDx4bnMSYfGru', + consumed_milligas: '1100000', + }, + operations: [ + [ + { + protocol: 'PtLimaPtLMwfNinJi9rCfDPWea8dFgTZ1MeJ9f1m2SRic6ayiwW', + chain_id: 'NetXizpkH94bocH', + hash: 'opT8tdDhEafJu7qrzsdtwSqP1LcD9rKCNG7DoVT59vQV1JdxUu3', + branch: 'BKtKnh7dkSaZyRbAhRL8vF4ZT1SDKRvXptBQ4pKEh6pbmKE7yf4', + contents: [ + { + kind: 'endorsement', + slot: 0, + level: 104427, + round: 0, + block_payload_hash: 'vh2zfP3jrzMXxabzESqDmMvSf6iStm9gW6TwsQHscCa423YbrULT', + metadata: { + delegate: 'tz3Q67aMz7gSMiQRcW729sXSfuMtkyAHYfqc', + endorsement_power: 316, + consensus_key: 'tz3Q67aMz7gSMiQRcW729sXSfuMtkyAHYfqc', + }, + }, + ], + signature: + 'sigRk4JF7pC3BcfqqPYqdPvv3yAuxJBfUkTMqnx6oDDm6WZZggH7DLkyJMFennY1AaXtprhHBgFtnVptfxPYGRLYLYutqggG', + }, + ], + [], + [], + [ + { + protocol: 'PtLimaPtLMwfNinJi9rCfDPWea8dFgTZ1MeJ9f1m2SRic6ayiwW', + chain_id: 'NetXizpkH94bocH', + hash: 'opNzjyNGHBAgvsVMyezUAPSZKbFcXZmTh6GTjcTjAGtGMpVG3Eh', + branch: 'BM6qkBbRP17B4UeQAFJBzWyPuy2bxEbKHGbUiP97xihMeeRywzW', + contents: [ + { + kind: 'update_consensus_key', + source: 'tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv', + fee: '369', + counter: '19043', + gas_limit: '1100', + storage_limit: '0', + pk: 'edpkti5K5JbdLpp2dCqiTLoLQqs5wqzeVhfHVnNhsSCuoU8zdHYoY7', + metadata: { + balance_updates: [ + { + kind: 'contract', + contract: 'tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv', + change: '-369', + origin: 'block', + }, + { + kind: 'accumulator', + category: 'block fees', + change: '369', + origin: 'block', + }, + ], + operation_result: { + status: 'applied', + consumed_gas: '1000', + consumed_milligas: '1000000', + }, + }, + }, + { + kind: 'drain_delegate', + consensus_key: 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj', + delegate: 'tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv', + destination: 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj', + metadata: { + balance_updates: [ + { + kind: 'contract', + contract: 'tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv', + change: '-15525772494', + origin: 'block', + }, + { + kind: 'contract', + contract: 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj', + change: '15525772494', + origin: 'block', + }, + { + kind: 'contract', + contract: 'tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv', + change: '-156825984', + origin: 'block', + }, + { + kind: 'contract', + contract: 'tz1hoyMUiJYYr4FRPMU8Z7WJzYkqgjygjaTy', + change: '156825984', + origin: 'block', + }, + ], + }, + }, + ], + signature: + 'sigrsWF7LpFpUBrTdvLnKm8DMuijk1LcZovZdKZDgsaafTPZhKsvLzPFHDzZYKCy4kobkgxVL7YPGnU5qzJJBcP2cAu5HW1C', + }, + ], + ], +}; + export const blockMondaynetSample = { protocol: 'ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK', chain_id: 'NetXrxsLyu6hTHx', diff --git a/packages/taquito-rpc/test/taquito-rpc.spec.ts b/packages/taquito-rpc/test/taquito-rpc.spec.ts index 40990786ca..a047720f02 100644 --- a/packages/taquito-rpc/test/taquito-rpc.spec.ts +++ b/packages/taquito-rpc/test/taquito-rpc.spec.ts @@ -30,11 +30,14 @@ import { OperationResultEvent, OperationContentsAndResultTransferTicket, OperationContentsAndResultTxRollupReturnBond, + OperationContentsAndResultUpdateConsensusKey, + OperationContentsAndResultDrainDelegate, } from '../src/types'; import { blockIthacanetSample, blockJakartanetSample, blockKathmandunetSample, + blockLimanetSample, blockMondaynetSample, delegatesIthacanetSample, delegatesKathmandunetSample, @@ -3215,6 +3218,86 @@ describe('RpcClient test', () => { done(); }); + + it('should be able to access the properties of operation type drain_delegate, proto15', async (done) => { + httpBackend.createRequest.mockReturnValue(Promise.resolve(blockLimanetSample)); + + const response = await client.getBlock(); + const content = response.operations[3][0] + .contents[1] as OperationContentsAndResultDrainDelegate; + + expect(content.kind).toEqual(OpKind.DRAIN_DELEGATE); + expect(content.consensus_key).toEqual('tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj'); + expect(content.delegate).toEqual('tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv'); + expect(content.destination).toEqual('tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj'); + + expect(content.metadata.balance_updates).toBeDefined(); + + expect(content.metadata.balance_updates![0].kind).toEqual('contract'); + expect(content.metadata.balance_updates![0].contract).toEqual( + 'tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv' + ); + expect(content.metadata.balance_updates![0].change).toEqual('-15525772494'); + expect(content.metadata.balance_updates![0].origin).toEqual('block'); + + expect(content.metadata.balance_updates![1].kind).toEqual('contract'); + expect(content.metadata.balance_updates![1].contract).toEqual( + 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj' + ); + expect(content.metadata.balance_updates![1].change).toEqual('15525772494'); + expect(content.metadata.balance_updates![1].origin).toEqual('block'); + + expect(content.metadata.balance_updates![2].kind).toEqual('contract'); + expect(content.metadata.balance_updates![2].contract).toEqual( + 'tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv' + ); + expect(content.metadata.balance_updates![2].change).toEqual('-156825984'); + expect(content.metadata.balance_updates![2].origin).toEqual('block'); + + expect(content.metadata.balance_updates![3].kind).toEqual('contract'); + expect(content.metadata.balance_updates![3].contract).toEqual( + 'tz1hoyMUiJYYr4FRPMU8Z7WJzYkqgjygjaTy' + ); + expect(content.metadata.balance_updates![3].change).toEqual('156825984'); + expect(content.metadata.balance_updates![3].origin).toEqual('block'); + + done(); + }); + + it('should be able to access the properties of operation type update_consensus_key, proto15', async (done) => { + httpBackend.createRequest.mockReturnValue(Promise.resolve(blockLimanetSample)); + + const response = await client.getBlock(); + const content = response.operations[3][0] + .contents[0] as OperationContentsAndResultUpdateConsensusKey; + + expect(content.kind).toEqual(OpKind.UPDATE_CONSENSUS_KEY); + expect(content.source).toEqual('tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv'); + expect(content.fee).toEqual('369'); + expect(content.counter).toEqual('19043'); + expect(content.gas_limit).toEqual('1100'); + expect(content.storage_limit).toEqual('0'); + expect(content.pk).toEqual('edpkti5K5JbdLpp2dCqiTLoLQqs5wqzeVhfHVnNhsSCuoU8zdHYoY7'); + + expect(content.metadata.balance_updates).toBeDefined(); + + expect(content.metadata.balance_updates![0].kind).toEqual('contract'); + expect(content.metadata.balance_updates![0].contract).toEqual( + 'tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv' + ); + expect(content.metadata.balance_updates![0].change).toEqual('-369'); + expect(content.metadata.balance_updates![0].origin).toEqual('block'); + + expect(content.metadata.balance_updates![1].kind).toEqual('accumulator'); + expect(content.metadata.balance_updates![1].category).toEqual('block fees'); + expect(content.metadata.balance_updates![1].change).toEqual('369'); + expect(content.metadata.balance_updates![1].origin).toEqual('block'); + + expect(content.metadata.operation_result.status).toEqual('applied'); + expect(content.metadata.operation_result.consumed_gas).toEqual('1000'); + expect(content.metadata.operation_result.consumed_milligas).toEqual('1000000'); + done(); + }); }); describe('getBakingRights', () => {