From 5bcc91568f8706e2631bd39b64b309fe5d864d88 Mon Sep 17 00:00:00 2001 From: Roxane Letourneau Date: Fri, 7 May 2021 17:10:27 -0700 Subject: [PATCH] Added type for operation endorsement_with_slot --- packages/taquito-rpc/src/opkind.ts | 1 + packages/taquito-rpc/src/types.ts | 23 ++++- packages/taquito-rpc/test/taquito-rpc.spec.ts | 89 ++++++++++++++++++- 3 files changed, 110 insertions(+), 3 deletions(-) diff --git a/packages/taquito-rpc/src/opkind.ts b/packages/taquito-rpc/src/opkind.ts index 7e4999b6f5..f99b728ad1 100644 --- a/packages/taquito-rpc/src/opkind.ts +++ b/packages/taquito-rpc/src/opkind.ts @@ -5,6 +5,7 @@ export enum OpKind { TRANSACTION = 'transaction', ACTIVATION = 'activate_account', ENDORSEMENT = 'endorsement', + ENDORSEMENT_WITH_SLOT = 'endorsement_with_slot', SEED_NONCE_REVELATION = 'seed_nonce_revelation', DOUBLE_ENDORSEMENT_EVIDENCE = 'double_endorsement_evidence', DOUBLE_BAKING_EVIDENCE = 'double_baking_evidence', diff --git a/packages/taquito-rpc/src/types.ts b/packages/taquito-rpc/src/types.ts index 6f7130d357..fc0f0134aa 100644 --- a/packages/taquito-rpc/src/types.ts +++ b/packages/taquito-rpc/src/types.ts @@ -66,6 +66,12 @@ export interface OperationContentsEndorsement { level: number; } +export interface OperationContentsEndorsementWithSlot { + kind: OpKind.ENDORSEMENT_WITH_SLOT; + endorsement: InlinedEndorsement; + slot: number; +} + export interface OperationContentsRevelation { kind: OpKind.SEED_NONCE_REVELATION; level: number; @@ -76,6 +82,7 @@ export interface OperationContentsDoubleEndorsement { kind: OpKind.DOUBLE_ENDORSEMENT_EVIDENCE; op1: InlinedEndorsement; op2: InlinedEndorsement; + slot?: number; } export interface OperationContentsDoubleBaking { @@ -160,7 +167,8 @@ export type OperationContents = | OperationContentsReveal | OperationContentsTransaction | OperationContentsOrigination - | OperationContentsDelegation; + | OperationContentsDelegation + | OperationContentsEndorsementWithSlot; export interface OperationContentsAndResultMetadataExtended { balance_updates: OperationMetadataBalanceUpdates[]; @@ -196,6 +204,13 @@ export interface OperationContentsAndResultEndorsement { metadata: OperationContentsAndResultMetadataExtended; } +export interface OperationContentsAndResultEndorsementWithSlot { + kind: OpKind.ENDORSEMENT_WITH_SLOT; + endorsement: InlinedEndorsement; + slot: number; + metadata: OperationContentsAndResultMetadataExtended; +} + export interface OperationContentsAndResultRevelation { kind: OpKind.SEED_NONCE_REVELATION; level: number; @@ -207,6 +222,7 @@ export interface OperationContentsAndResultDoubleEndorsement { kind: OpKind.DOUBLE_ENDORSEMENT_EVIDENCE; op1: InlinedEndorsement; op2: InlinedEndorsement; + slot?: number; metadata: OperationContentsAndResultMetadata; } @@ -285,7 +301,8 @@ export type OperationContentsAndResult = | OperationContentsAndResultReveal | OperationContentsAndResultTransaction | OperationContentsAndResultOrigination - | OperationContentsAndResultDelegation; + | OperationContentsAndResultDelegation + | OperationContentsAndResultEndorsementWithSlot; export interface OperationEntry { protocol: string; @@ -549,6 +566,7 @@ export interface InternalOperationResult { export type MetadataBalanceUpdatesKindEnum = 'contract' | 'freezer'; export type MetadataBalanceUpdatesCategoryEnum = 'rewards' | 'fees' | 'deposits'; +export type MetadataBalanceUpdatesOriginEnum = 'block' | 'migration'; export interface OperationMetadataBalanceUpdates { kind: MetadataBalanceUpdatesKindEnum; @@ -557,6 +575,7 @@ export interface OperationMetadataBalanceUpdates { delegate?: string; cycle?: number; change: string; + origin?: MetadataBalanceUpdatesOriginEnum; } export type OperationResultStatusEnum = 'applied' | 'failed' | 'skipped' | 'backtracked'; diff --git a/packages/taquito-rpc/test/taquito-rpc.spec.ts b/packages/taquito-rpc/test/taquito-rpc.spec.ts index 56cb0383fe..3d8e02c9bd 100644 --- a/packages/taquito-rpc/test/taquito-rpc.spec.ts +++ b/packages/taquito-rpc/test/taquito-rpc.spec.ts @@ -1,6 +1,6 @@ import { RpcClient } from '../src/taquito-rpc'; import BigNumber from 'bignumber.js'; -import { OperationContentsAndResultEndorsement } from '../src/types'; +import { OperationContentsAndResultEndorsement, OperationContentsAndResultEndorsementWithSlot } from '../src/types'; import { OperationContentsAndResultTransaction } from '../src/types'; /** @@ -1042,6 +1042,93 @@ describe('RpcClient test', () => { expect(transaction.metadata.operation_result.consumed_gas).toEqual('24660'); done(); }); + + it('query the right url and property for operation, proto 9, endorsement_with_slot', async done => { + httpBackend.createRequest.mockReturnValue( + Promise.resolve({ + "protocol": "PsFLorenaUUuikDWvMDr6fGBRG8kt3e3D3fHoXK1j1BFRxeSH4i", + "chain_id": "NetXxkAx4woPLyu", + "hash": "BLRWVvWTrqgUt1JL76RnUguKhkqfbHnXVrznXpuCrhxemSuCrb3", + "header": { + "level": 174209, + "proto": 1, + "predecessor": "BMarN3hiEmCrSrfeo6qndubHe9FXpPy4qcj3Xr2NBGGfG4Tfcaj", + "timestamp": "2021-05-07T18:37:59Z", + "validation_pass": 4, + "operations_hash": "LLoaFb5cQjcr2pzKbLsmhPN2NgLY5gGs9ePimjRsNyCtgAQejfbXg", + "fitness": ["01", "000000000002a880"], + "context": "CoWMJU1LmpfMn92zz4Ah1TrwXaSHnRWcy8dcso32AH7miULKad1d", + "priority": 0, + "proof_of_work_nonce": "08351e3d59170e00", + "signature": "sigg9pz9Q5i17nDZpZ3mbbMQsLHNuHX3SxTxHguLwgR9xYL2x17TmH7QfVFsadQTa61QCnq5vuFXkFtymeQKNh74VsWnMu9D" + }, + "metadata": {}, + "operations": [ + [ + { + "protocol": "PsFLorenaUUuikDWvMDr6fGBRG8kt3e3D3fHoXK1j1BFRxeSH4i", + "chain_id": "NetXxkAx4woPLyu", + "hash": "ooYSSxYcgreJQtrzxqyBpBdCntVbnbvHdtqA7RZsFcSDz4XFZJY", + "branch": "BMarN3hiEmCrSrfeo6qndubHe9FXpPy4qcj3Xr2NBGGfG4Tfcaj", + "contents": [ + { + "kind": "endorsement_with_slot", + "endorsement": { + "branch": "BMarN3hiEmCrSrfeo6qndubHe9FXpPy4qcj3Xr2NBGGfG4Tfcaj", + "operations": { "kind": "endorsement", "level": 174208 }, + "signature": "signiPFVn2gFXvu7dKxEnifWQgbzan9ca6z7XSS5PyNBin2BufNBTFz9hgM7imvWf2HSj6NY3ECtEvb5xmwiYnUDbpSTUQC6" + }, + "slot": 4, + "metadata": { + "balance_updates": [ + { + "kind": "contract", + "contract": "tz1VWasoyFGAWZt5K2qZRzP3cWzv3z7MMhP8", + "change": "-320000000", + "origin": "block" + }, + { + "kind": "freezer", + "category": "deposits", + "delegate": "tz1VWasoyFGAWZt5K2qZRzP3cWzv3z7MMhP8", + "cycle": 85, + "change": "320000000", + "origin": "block" + }, + { + "kind": "freezer", + "category": "rewards", + "delegate": "tz1VWasoyFGAWZt5K2qZRzP3cWzv3z7MMhP8", + "cycle": 85, + "change": "6250000", + "origin": "block" + } + ], + "delegate": "tz1VWasoyFGAWZt5K2qZRzP3cWzv3z7MMhP8", + "slots": [4, 11, 18, 21, 24] + } + } + ] + } + ] + ] + } + ) + ); + + const response = await client.getBlock(); + + expect(httpBackend.createRequest.mock.calls[0][0]).toEqual({ + method: 'GET', + url: 'root/chains/test/blocks/head', + }); + const endorsementWithSlot = response.operations[0][0] + .contents[0] as OperationContentsAndResultEndorsementWithSlot; + expect(endorsementWithSlot.kind).toEqual('endorsement_with_slot'); + expect(endorsementWithSlot.metadata.slots).toEqual([4, 11, 18, 21, 24]); + expect(endorsementWithSlot.slot).toEqual(4); + done(); + }); }); describe('getBakingRights', () => {