From 0210b1b94b5f53d61d27aef55d9b1bb2fc59bac4 Mon Sep 17 00:00:00 2001 From: huianyang Date: Thu, 2 May 2024 14:43:09 -0700 Subject: [PATCH 1/4] feat: added rpc type of attestation_with_dal & endorsement_with_dal --- packages/taquito-rpc/src/opkind.ts | 4 +- packages/taquito-rpc/src/types.ts | 47 +++-- packages/taquito-rpc/test/taquito-rpc.spec.ts | 174 +++++++++--------- 3 files changed, 118 insertions(+), 107 deletions(-) diff --git a/packages/taquito-rpc/src/opkind.ts b/packages/taquito-rpc/src/opkind.ts index 80b6a47c21..3b9e3ebb58 100644 --- a/packages/taquito-rpc/src/opkind.ts +++ b/packages/taquito-rpc/src/opkind.ts @@ -11,8 +11,8 @@ export enum OpKind { SET_DEPOSITS_LIMIT = 'set_deposits_limit', DOUBLE_PREATTESTATION_EVIDENCE = 'double_preattestation_evidence', DOUBLE_PREENDORSEMENT_EVIDENCE = 'double_preendorsement_evidence', - ATTESTATION_WITH_SLOT = 'attestation_with_slot', - ENDORSEMENT_WITH_SLOT = 'endorsement_with_slot', + ATTESTATION_WITH_DAL = 'attestation_with_dal', + ENDORSEMENT_WITH_DAL = 'endorsement_with_dal', SEED_NONCE_REVELATION = 'seed_nonce_revelation', DOUBLE_ATTESTATION_EVIDENCE = 'double_attestation_evidence', DOUBLE_ENDORSEMENT_EVIDENCE = 'double_endorsement_evidence', diff --git a/packages/taquito-rpc/src/types.ts b/packages/taquito-rpc/src/types.ts index 5b501b3a9c..4d6bf03cb6 100644 --- a/packages/taquito-rpc/src/types.ts +++ b/packages/taquito-rpc/src/types.ts @@ -247,16 +247,22 @@ export interface OperationContentsSetDepositsLimit { limit?: string; } -export interface OperationContentsAttestationWithSlot { - kind: OpKind.ATTESTATION_WITH_SLOT; - endorsement: InlinedAttestation; +export interface OperationContentsAttestationWithDal { + kind: OpKind.ATTESTATION_WITH_DAL; slot: number; + level: number; + round: number; + block_payload_hash: string; + dal_attestation: string; } -export interface OperationContentsEndorsementWithSlot { - kind: OpKind.ENDORSEMENT_WITH_SLOT; - endorsement: InlinedEndorsement; +export interface OperationContentsEndorsementWithDal { + kind: OpKind.ENDORSEMENT_WITH_DAL; slot: number; + level: number; + round: number; + block_payload_hash: string; + dal_attestation: string; } export interface OperationContentsRevelation { @@ -523,8 +529,8 @@ export type OperationContents = | OperationContentsTransaction | OperationContentsOrigination | OperationContentsDelegation - | OperationContentsAttestationWithSlot - | OperationContentsEndorsementWithSlot + | OperationContentsAttestationWithDal + | OperationContentsEndorsementWithDal | OperationContentsFailingNoop | OperationContentsRegisterGlobalConstant | OperationContentsSetDepositsLimit @@ -551,8 +557,7 @@ export interface OperationContentsAndResultMetadataExtended1 { export interface OperationContentsAndResultMetadataExtended0 { balance_updates?: OperationMetadataBalanceUpdates[]; delegate: string; - slots?: number[]; - endorsement_power?: number; + endorsement_power: number; consensus_key?: string; } @@ -718,10 +723,13 @@ export interface OperationContentsAndResultDoublePreattestation { metadata: OperationContentsAndResultMetadata; } -export interface OperationContentsAndResultAttestationWithSlot { - kind: OpKind.ATTESTATION_WITH_SLOT; - endorsement: InlinedAttestation; +export interface OperationContentsAndResultAttestationWithDal { + kind: OpKind.ATTESTATION_WITH_DAL; slot: number; + level: number; + round: number; + block_payload_hash: string; + dal_attestation: string; metadata: OperationContentsAndResultMetadataExtended1; } @@ -732,10 +740,13 @@ export interface OperationContentsAndResultDoublePreEndorsement { metadata: OperationContentsAndResultMetadata; } -export interface OperationContentsAndResultEndorsementWithSlot { - kind: OpKind.ENDORSEMENT_WITH_SLOT; - endorsement: InlinedEndorsement; +export interface OperationContentsAndResultEndorsementWithDal { + kind: OpKind.ENDORSEMENT_WITH_DAL; slot: number; + level: number; + round: number; + block_payload_hash: string; + dal_attestation: string; metadata: OperationContentsAndResultMetadataExtended0; } @@ -1017,8 +1028,8 @@ export type OperationContentsAndResult = | OperationContentsAndResultTransaction | OperationContentsAndResultOrigination | OperationContentsAndResultDelegation - | OperationContentsAndResultAttestationWithSlot - | OperationContentsAndResultEndorsementWithSlot + | OperationContentsAndResultAttestationWithDal + | OperationContentsAndResultEndorsementWithDal | OperationContentsAndResultRegisterGlobalConstant | OperationContentsAndResultSetDepositsLimit | OperationContentsAndResultTransferTicket diff --git a/packages/taquito-rpc/test/taquito-rpc.spec.ts b/packages/taquito-rpc/test/taquito-rpc.spec.ts index a2ccb5360c..b9402e88a7 100644 --- a/packages/taquito-rpc/test/taquito-rpc.spec.ts +++ b/packages/taquito-rpc/test/taquito-rpc.spec.ts @@ -5,7 +5,7 @@ import BigNumber from 'bignumber.js'; import { LazyStorageDiffBigMap, OperationContentsAndResultEndorsement, - OperationContentsAndResultEndorsementWithSlot, + // OperationContentsAndResultEndorsementWithDal, OperationContentsAndResultOrigination, OperationResultTransaction, OperationContentsAndResultTransaction, @@ -1788,92 +1788,92 @@ describe('RpcClient test', () => { expect(transaction.metadata.operation_result.consumed_gas).toEqual('24660'); }); - it('should query the right url and property for operation, proto 9, endorsement_with_slot', async () => { - 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); - }); + // it('should query the right url and property for operation, proto 9, endorsement_with_slot', async () => { + // 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); + // }); it('should query the right url and properties (big_map_diff and lazy_storage_diff) in transaction operation result, proto 9', async () => { httpBackend.createRequest.mockReturnValue( From 3b7ed7a674789ea0ec09c0a6db16dba85eb56ec5 Mon Sep 17 00:00:00 2001 From: huianyang Date: Thu, 2 May 2024 15:09:42 -0700 Subject: [PATCH 2/4] feat: added local-forger support of attestation_with_dal --- .../__tests__/local-forging.spec.ts | 18 ++++++++++++++---- integration-tests/data/allTestsCases.ts | 18 ++++++++++++++++++ .../taquito-local-forging/src/constants.ts | 3 ++- packages/taquito-local-forging/src/decoder.ts | 6 +++--- packages/taquito-local-forging/src/encoder.ts | 5 +++-- .../src/schema/operation.ts | 3 ++- .../taquito-local-forging/src/validator.ts | 6 +++--- 7 files changed, 45 insertions(+), 14 deletions(-) diff --git a/integration-tests/__tests__/local-forging.spec.ts b/integration-tests/__tests__/local-forging.spec.ts index caea007eb1..c00142b85a 100644 --- a/integration-tests/__tests__/local-forging.spec.ts +++ b/integration-tests/__tests__/local-forging.spec.ts @@ -1,5 +1,5 @@ import { CONFIGS } from "../config"; -import { commonCases, oxfordCases } from '../data/allTestsCases'; +import { commonCases, oxfordCases, parisCases } from '../data/allTestsCases'; import { LocalForger, ProtocolsHash } from '@taquito/local-forging' import { Protocols, TezosToolkit } from "@taquito/taquito"; import { ProtoGreaterOrEqual } from '@taquito/michel-codec'; @@ -7,9 +7,20 @@ import { ProtoGreaterOrEqual } from '@taquito/michel-codec'; CONFIGS().forEach(({ rpc, protocol }) => { const Tezos = new TezosToolkit(rpc); const oxfordAndAlpha = ProtoGreaterOrEqual(protocol, Protocols.ProxfordY) ? test : test.skip + const parisAndAlpha = ProtoGreaterOrEqual(protocol, Protocols.PtParisBQ) ? test : test.skip describe(`Test local forger: ${rpc}`, () => { - // all protocols + parisCases.forEach(({ name, operation, expected }) => { + parisAndAlpha(`Verify that .forge for local forge will return same result as for network forge for rpc: ${name} (${rpc})`, async () => { + const localForger = new LocalForger(protocol as unknown as ProtocolsHash); + const result = await localForger.forge(operation); + const rpcResult = await Tezos.rpc.forgeOperations(operation); + console.log('local', result) + console.log('rpc', rpcResult) + expect(result).toEqual(rpcResult); + expect(await localForger.parse(result)).toEqual(expected || operation); + }); + }); oxfordCases.forEach(({ name, operation, expected }) => { oxfordAndAlpha(`Verify that .forge for local forge will return same result as for network forge for rpc: ${name} (${rpc})`, async () => { const localForger = new LocalForger(protocol as unknown as ProtocolsHash); @@ -17,10 +28,9 @@ CONFIGS().forEach(({ rpc, protocol }) => { const rpcResult = await Tezos.rpc.forgeOperations(operation); expect(result).toEqual(rpcResult); expect(await localForger.parse(result)).toEqual(expected || operation); - }); }); - + // all protocols commonCases.forEach(({ name, operation, expected }) => { it(`Verify that .forge for local forge will return same result as for network forge for rpc: ${name} (${rpc})`, async () => { const localForger = new LocalForger(protocol as unknown as ProtocolsHash); diff --git a/integration-tests/data/allTestsCases.ts b/integration-tests/data/allTestsCases.ts index 7bec96eb48..9b624df795 100644 --- a/integration-tests/data/allTestsCases.ts +++ b/integration-tests/data/allTestsCases.ts @@ -49,6 +49,24 @@ interface TestCase { expected?: object; } +export const parisCases: TestCase[] = [ + { + name: 'Attestation With Dal operation', + operation: { + branch: 'BLzyjjHKEKMULtvkpSHxuZxx6ei6fpntH2BTkYZiLgs8zLVstvX', + contents: [ + { + kind: OpKind.ATTESTATION_WITH_DAL, + slot: 0, + level: 66299, + round: 5, + block_payload_hash: 'vh3FEkypvxUYLwjGYd2Sme7aWyfX8npDsqxcL6imVpBWnAZeNn2n', + dal_attestation: '10' + } + ] + } + }, +] export const oxfordCases: TestCase[] = [ { name: 'Origination of a contract that contains the types chest, chest_key and the instruction OPEN_CHEST', diff --git a/packages/taquito-local-forging/src/constants.ts b/packages/taquito-local-forging/src/constants.ts index 666716b799..50b461d51e 100644 --- a/packages/taquito-local-forging/src/constants.ts +++ b/packages/taquito-local-forging/src/constants.ts @@ -43,7 +43,7 @@ export enum CODEC { OP_BALLOT = 'ballot', OP_FAILING_NOOP = 'failing_noop', OP_ATTESTATION = 'attestation', - OP_ENDORSEMENT = 'endorsement', + OP_ATTESTATION_WITH_DAL = 'attestation_with_dal', OP_SEED_NONCE_REVELATION = 'seed_nonce_revelation', OP_REVEAL = 'reveal', OP_PROPOSALS = 'proposals', @@ -239,6 +239,7 @@ export const kindMapping: { [key: number]: string } = { 0x6d: 'origination', 0x06: 'ballot', 0x15: 'attestation', + 0x17: 'attestation_with_dal', 0x01: 'seed_nonce_revelation', 0x05: 'proposals', 0x6f: 'register_global_constant', diff --git a/packages/taquito-local-forging/src/decoder.ts b/packages/taquito-local-forging/src/decoder.ts index 0bcfb7c212..d0c621b9d1 100644 --- a/packages/taquito-local-forging/src/decoder.ts +++ b/packages/taquito-local-forging/src/decoder.ts @@ -32,7 +32,7 @@ import { BallotSchema, DelegationSchema, AttestationSchema, - EndorsementSchema, + AttestationWithDalSchema, IncreasePaidStorageSchema, UpdateConsensusKeySchema, DrainDelegateSchema, @@ -102,8 +102,8 @@ decoders[CODEC.OP_ORIGINATION] = (val: Uint8ArrayConsumer) => decoders[CODEC.OP_BALLOT] = (val: Uint8ArrayConsumer) => schemaDecoder(decoders)(BallotSchema)(val); decoders[CODEC.OP_ATTESTATION] = (val: Uint8ArrayConsumer) => schemaDecoder(decoders)(AttestationSchema)(val); -decoders[CODEC.OP_ENDORSEMENT] = (val: Uint8ArrayConsumer) => - schemaDecoder(decoders)(EndorsementSchema)(val); +decoders[CODEC.OP_ATTESTATION_WITH_DAL] = (val: Uint8ArrayConsumer) => + schemaDecoder(decoders)(AttestationWithDalSchema)(val); decoders[CODEC.OP_SEED_NONCE_REVELATION] = (val: Uint8ArrayConsumer) => schemaDecoder(decoders)(SeedNonceRevelationSchema)(val); decoders[CODEC.OP_PROPOSALS] = (val: Uint8ArrayConsumer) => diff --git a/packages/taquito-local-forging/src/encoder.ts b/packages/taquito-local-forging/src/encoder.ts index 96f7f99133..d8f96b818a 100644 --- a/packages/taquito-local-forging/src/encoder.ts +++ b/packages/taquito-local-forging/src/encoder.ts @@ -32,7 +32,7 @@ import { BallotSchema, DelegationSchema, AttestationSchema, - EndorsementSchema, + AttestationWithDalSchema, IncreasePaidStorageSchema, UpdateConsensusKeySchema, DrainDelegateSchema, @@ -93,7 +93,8 @@ encoders[CODEC.OP_TRANSACTION] = (val: any) => schemaEncoder(encoders)(Transacti encoders[CODEC.OP_ORIGINATION] = (val: any) => schemaEncoder(encoders)(OriginationSchema)(val); encoders[CODEC.OP_BALLOT] = (val: any) => schemaEncoder(encoders)(BallotSchema)(val); encoders[CODEC.OP_ATTESTATION] = (val: any) => schemaEncoder(encoders)(AttestationSchema)(val); -encoders[CODEC.OP_ENDORSEMENT] = (val: any) => schemaEncoder(encoders)(EndorsementSchema)(val); +encoders[CODEC.OP_ATTESTATION_WITH_DAL] = (val: any) => + schemaEncoder(encoders)(AttestationWithDalSchema)(val); encoders[CODEC.OP_SEED_NONCE_REVELATION] = (val: any) => schemaEncoder(encoders)(SeedNonceRevelationSchema)(val); encoders[CODEC.OP_PROPOSALS] = (val: any) => schemaEncoder(encoders)(ProposalsSchema)(val); diff --git a/packages/taquito-local-forging/src/schema/operation.ts b/packages/taquito-local-forging/src/schema/operation.ts index 3e9640065b..920bdef3e8 100644 --- a/packages/taquito-local-forging/src/schema/operation.ts +++ b/packages/taquito-local-forging/src/schema/operation.ts @@ -72,11 +72,12 @@ export const AttestationSchema = { block_payload_hash: CODEC.BLOCK_PAYLOAD_HASH, }; -export const EndorsementSchema = { +export const AttestationWithDalSchema = { slot: CODEC.INT16, level: CODEC.INT32, round: CODEC.INT32, block_payload_hash: CODEC.BLOCK_PAYLOAD_HASH, + dal_attestation: CODEC.ZARITH, }; export const SeedNonceRevelationSchema = { diff --git a/packages/taquito-local-forging/src/validator.ts b/packages/taquito-local-forging/src/validator.ts index 59d277f634..7d7a51e3d8 100644 --- a/packages/taquito-local-forging/src/validator.ts +++ b/packages/taquito-local-forging/src/validator.ts @@ -11,7 +11,7 @@ import { RevealSchema, RegisterGlobalConstantSchema, AttestationSchema, - EndorsementSchema, + AttestationWithDalSchema, TransferTicketSchema, IncreasePaidStorageSchema, UpdateConsensusKeySchema, @@ -31,7 +31,7 @@ type OperationKind = | OpKind.ORIGINATION | OpKind.BALLOT | OpKind.ATTESTATION - | OpKind.ENDORSEMENT + | OpKind.ATTESTATION_WITH_DAL | OpKind.SEED_NONCE_REVELATION | OpKind.PROPOSALS | OpKind.REGISTER_GLOBAL_CONSTANT @@ -52,7 +52,7 @@ const OperationKindMapping = { origination: OriginationSchema, ballot: BallotSchema, attestation: AttestationSchema, - endorsement: EndorsementSchema, + attestation_with_dal: AttestationWithDalSchema, seed_nonce_revelation: SeedNonceRevelationSchema, proposals: ProposalsSchema, register_global_constant: RegisterGlobalConstantSchema, From 30e963bf4030ed5ae2b532bde58fa1660cd12652 Mon Sep 17 00:00:00 2001 From: huianyang Date: Mon, 6 May 2024 11:11:57 -0700 Subject: [PATCH 3/4] test: added unit tests --- packages/taquito-rpc/test/taquito-rpc.spec.ts | 154 ++++++++---------- 1 file changed, 67 insertions(+), 87 deletions(-) diff --git a/packages/taquito-rpc/test/taquito-rpc.spec.ts b/packages/taquito-rpc/test/taquito-rpc.spec.ts index b9402e88a7..c4007fbbba 100644 --- a/packages/taquito-rpc/test/taquito-rpc.spec.ts +++ b/packages/taquito-rpc/test/taquito-rpc.spec.ts @@ -5,7 +5,7 @@ import BigNumber from 'bignumber.js'; import { LazyStorageDiffBigMap, OperationContentsAndResultEndorsement, - // OperationContentsAndResultEndorsementWithDal, + OperationContentsAndResultAttestationWithDal, OperationContentsAndResultOrigination, OperationResultTransaction, OperationContentsAndResultTransaction, @@ -1788,92 +1788,72 @@ describe('RpcClient test', () => { expect(transaction.metadata.operation_result.consumed_gas).toEqual('24660'); }); - // it('should query the right url and property for operation, proto 9, endorsement_with_slot', async () => { - // 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); - // }); + it('should query the right url and property for operation, proto 20, attestation_with_dal', async () => { + httpBackend.createRequest.mockReturnValue( + Promise.resolve({ + protocol: 'PtParisBQscdCm6Cfow6ndeU6wKJyA3aV1j4D3gQBQMsTQyJCrz', + chain_id: 'NetXo8SqH1c38SS', + hash: 'BKsCfYZrh417adJiKbGsyhVG2XrvUBJDhhkCAkZQzWzkEHCejXr', + header: { + level: 416914, + proto: 2, + predecessor: 'BLBXzegi3m1K8YjP7w9YgEpts5a9ZCFjY7xqRcm16p6yFxXbZGT', + timestamp: '2024-05-06T18:01:07Z', + validation_pass: 4, + operations_hash: 'LLoZxmgEJQyZ74XCrZQu8Jtcov4SnGGRyuYf32fYmURW2Xfcj58Gv', + fitness: ['02', '00065c92', '', 'ffffffff', '00000000'], + context: 'CoV1GGrMBca5uBG4AzQbKNrQhQHHTtSYJAHVk7pJtuMw3uWiNvTV', + payload_hash: 'vh1mfavAuf7E1m1tZUEHkWomS8BDiLsVZz9T1A79Afu8Cag5DQHG', + payload_round: 0, + proof_of_work_nonce: 'e38cf66600000000', + liquidity_baking_toggle_vote: 'on', + adaptive_issuance_vote: 'on', + signature: + 'sighpgD4aPxorZUvPxKvBHYNvnQEBRctF14bYXFX9qLbXbCGZv64S1dFVduBLzWBSEXCcHWiBuUT1iLZt9SE2mKCTkLtWuo5', + }, + metadata: {}, + operations: [ + [ + { + protocol: 'PtParisBQscdCm6Cfow6ndeU6wKJyA3aV1j4D3gQBQMsTQyJCrz', + chain_id: 'NetXo8SqH1c38SS', + hash: 'opSmHyeasw4QcJ4Jc2qi6arNeSQMhFRjHBdFYWXGoMydLkgVRtb', + branch: 'BLHyjaqV2FhuHLQL3CBjWJqgZZ77BxcNxh3ehXcNYMQjjqAPwqA', + contents: [ + { + kind: 'attestation_with_dal', + slot: 19, + level: 416913, + round: 0, + block_payload_hash: 'vh27AvfjAJob9VdcZHEPHFbMAzi6nhCiHVzAyDBEdAPDCcEa676t', + dal_attestation: '0', + metadata: { + delegate: 'tz1Zt8QQ9aBznYNk5LUBjtME9DuExomw9YRs', + consensus_power: 532, + consensus_key: 'tz1Zt8QQ9aBznYNk5LUBjtME9DuExomw9YRs', + }, + }, + ], + signature: + 'sigh9rmktxbqmK6fXaq2ciAQrbrVH8pZhKeXEKHCzgNmJaP6gc1njofiMMzvhx2SRXQ7Gv8aVDzBM18kDGmUoBxQA693Bk2o', + }, + ], + ], + }) + ); + + 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 OperationContentsAndResultAttestationWithDal; + expect(endorsementWithSlot.kind).toEqual('attestation_with_dal'); + expect(endorsementWithSlot.slot).toEqual(19); + expect(endorsementWithSlot.dal_attestation).toEqual('0'); + }); it('should query the right url and properties (big_map_diff and lazy_storage_diff) in transaction operation result, proto 9', async () => { httpBackend.createRequest.mockReturnValue( From 013ccdcd873d21c7ebac591b03a2727f4c086765 Mon Sep 17 00:00:00 2001 From: huianyang Date: Mon, 6 May 2024 12:35:06 -0700 Subject: [PATCH 4/4] test: removed logging --- integration-tests/__tests__/local-forging.spec.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/integration-tests/__tests__/local-forging.spec.ts b/integration-tests/__tests__/local-forging.spec.ts index c00142b85a..990ca9f030 100644 --- a/integration-tests/__tests__/local-forging.spec.ts +++ b/integration-tests/__tests__/local-forging.spec.ts @@ -15,8 +15,6 @@ CONFIGS().forEach(({ rpc, protocol }) => { const localForger = new LocalForger(protocol as unknown as ProtocolsHash); const result = await localForger.forge(operation); const rpcResult = await Tezos.rpc.forgeOperations(operation); - console.log('local', result) - console.log('rpc', rpcResult) expect(result).toEqual(rpcResult); expect(await localForger.parse(result)).toEqual(expected || operation); });