Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2880 forger attestation with dal #2949

Merged
merged 12 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions integration-tests/__tests__/local-forging.spec.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
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';

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);
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);
const result = await localForger.forge(operation);
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);
Expand Down
18 changes: 18 additions & 0 deletions integration-tests/data/allTestsCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion packages/taquito-local-forging/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions packages/taquito-local-forging/src/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
BallotSchema,
DelegationSchema,
AttestationSchema,
EndorsementSchema,
AttestationWithDalSchema,
IncreasePaidStorageSchema,
UpdateConsensusKeySchema,
DrainDelegateSchema,
Expand Down Expand Up @@ -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) =>
Expand Down
5 changes: 3 additions & 2 deletions packages/taquito-local-forging/src/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
BallotSchema,
DelegationSchema,
AttestationSchema,
EndorsementSchema,
AttestationWithDalSchema,
IncreasePaidStorageSchema,
UpdateConsensusKeySchema,
DrainDelegateSchema,
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion packages/taquito-local-forging/src/schema/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions packages/taquito-local-forging/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
RevealSchema,
RegisterGlobalConstantSchema,
AttestationSchema,
EndorsementSchema,
AttestationWithDalSchema,
TransferTicketSchema,
IncreasePaidStorageSchema,
UpdateConsensusKeySchema,
Expand All @@ -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
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/taquito-rpc/src/opkind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
47 changes: 29 additions & 18 deletions packages/taquito-rpc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -523,8 +529,8 @@ export type OperationContents =
| OperationContentsTransaction
| OperationContentsOrigination
| OperationContentsDelegation
| OperationContentsAttestationWithSlot
| OperationContentsEndorsementWithSlot
| OperationContentsAttestationWithDal
| OperationContentsEndorsementWithDal
| OperationContentsFailingNoop
| OperationContentsRegisterGlobalConstant
| OperationContentsSetDepositsLimit
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -1017,8 +1028,8 @@ export type OperationContentsAndResult =
| OperationContentsAndResultTransaction
| OperationContentsAndResultOrigination
| OperationContentsAndResultDelegation
| OperationContentsAndResultAttestationWithSlot
| OperationContentsAndResultEndorsementWithSlot
| OperationContentsAndResultAttestationWithDal
| OperationContentsAndResultEndorsementWithDal
| OperationContentsAndResultRegisterGlobalConstant
| OperationContentsAndResultSetDepositsLimit
| OperationContentsAndResultTransferTicket
Expand Down
94 changes: 37 additions & 57 deletions packages/taquito-rpc/test/taquito-rpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import BigNumber from 'bignumber.js';
import {
LazyStorageDiffBigMap,
OperationContentsAndResultEndorsement,
OperationContentsAndResultEndorsementWithSlot,
OperationContentsAndResultAttestationWithDal,
OperationContentsAndResultOrigination,
OperationResultTransaction,
OperationContentsAndResultTransaction,
Expand Down Expand Up @@ -1788,74 +1788,54 @@ 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 () => {
it('should query the right url and property for operation, proto 20, attestation_with_dal', async () => {
httpBackend.createRequest.mockReturnValue(
Promise.resolve({
protocol: 'PsFLorenaUUuikDWvMDr6fGBRG8kt3e3D3fHoXK1j1BFRxeSH4i',
chain_id: 'NetXxkAx4woPLyu',
hash: 'BLRWVvWTrqgUt1JL76RnUguKhkqfbHnXVrznXpuCrhxemSuCrb3',
protocol: 'PtParisBQscdCm6Cfow6ndeU6wKJyA3aV1j4D3gQBQMsTQyJCrz',
chain_id: 'NetXo8SqH1c38SS',
hash: 'BKsCfYZrh417adJiKbGsyhVG2XrvUBJDhhkCAkZQzWzkEHCejXr',
header: {
level: 174209,
proto: 1,
predecessor: 'BMarN3hiEmCrSrfeo6qndubHe9FXpPy4qcj3Xr2NBGGfG4Tfcaj',
timestamp: '2021-05-07T18:37:59Z',
level: 416914,
proto: 2,
predecessor: 'BLBXzegi3m1K8YjP7w9YgEpts5a9ZCFjY7xqRcm16p6yFxXbZGT',
timestamp: '2024-05-06T18:01:07Z',
validation_pass: 4,
operations_hash: 'LLoaFb5cQjcr2pzKbLsmhPN2NgLY5gGs9ePimjRsNyCtgAQejfbXg',
fitness: ['01', '000000000002a880'],
context: 'CoWMJU1LmpfMn92zz4Ah1TrwXaSHnRWcy8dcso32AH7miULKad1d',
priority: 0,
proof_of_work_nonce: '08351e3d59170e00',
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:
'sigg9pz9Q5i17nDZpZ3mbbMQsLHNuHX3SxTxHguLwgR9xYL2x17TmH7QfVFsadQTa61QCnq5vuFXkFtymeQKNh74VsWnMu9D',
'sighpgD4aPxorZUvPxKvBHYNvnQEBRctF14bYXFX9qLbXbCGZv64S1dFVduBLzWBSEXCcHWiBuUT1iLZt9SE2mKCTkLtWuo5',
},
metadata: {},
operations: [
[
{
protocol: 'PsFLorenaUUuikDWvMDr6fGBRG8kt3e3D3fHoXK1j1BFRxeSH4i',
chain_id: 'NetXxkAx4woPLyu',
hash: 'ooYSSxYcgreJQtrzxqyBpBdCntVbnbvHdtqA7RZsFcSDz4XFZJY',
branch: 'BMarN3hiEmCrSrfeo6qndubHe9FXpPy4qcj3Xr2NBGGfG4Tfcaj',
protocol: 'PtParisBQscdCm6Cfow6ndeU6wKJyA3aV1j4D3gQBQMsTQyJCrz',
chain_id: 'NetXo8SqH1c38SS',
hash: 'opSmHyeasw4QcJ4Jc2qi6arNeSQMhFRjHBdFYWXGoMydLkgVRtb',
branch: 'BLHyjaqV2FhuHLQL3CBjWJqgZZ77BxcNxh3ehXcNYMQjjqAPwqA',
contents: [
{
kind: 'endorsement_with_slot',
endorsement: {
branch: 'BMarN3hiEmCrSrfeo6qndubHe9FXpPy4qcj3Xr2NBGGfG4Tfcaj',
operations: { kind: 'endorsement', level: 174208 },
signature:
'signiPFVn2gFXvu7dKxEnifWQgbzan9ca6z7XSS5PyNBin2BufNBTFz9hgM7imvWf2HSj6NY3ECtEvb5xmwiYnUDbpSTUQC6',
},
slot: 4,
kind: 'attestation_with_dal',
slot: 19,
level: 416913,
round: 0,
block_payload_hash: 'vh27AvfjAJob9VdcZHEPHFbMAzi6nhCiHVzAyDBEdAPDCcEa676t',
dal_attestation: '0',
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],
delegate: 'tz1Zt8QQ9aBznYNk5LUBjtME9DuExomw9YRs',
consensus_power: 532,
consensus_key: 'tz1Zt8QQ9aBznYNk5LUBjtME9DuExomw9YRs',
},
},
],
signature:
'sigh9rmktxbqmK6fXaq2ciAQrbrVH8pZhKeXEKHCzgNmJaP6gc1njofiMMzvhx2SRXQ7Gv8aVDzBM18kDGmUoBxQA693Bk2o',
},
],
],
Expand All @@ -1869,10 +1849,10 @@ describe('RpcClient test', () => {
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);
.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 () => {
Expand Down
Loading