Repository: ecadlabs/taquito
Pull request #1857 (2022-08-26 17:41:01)

feat(rpc): support new constant properties from the RPC for Kathmandu
Thank you for your contribution to Taquito.

Before submitting this PR, please make sure:

- [ ] Your code builds cleanly without any errors or warnings
- [ ] You have added unit tests
- [ ] You have added integration tests (if relevant/appropriate)
- [ ] All public methods or types have TypeDoc coverage with a complete description, and ideally an @example
- [ ] You have added or updated corresponding documentation
- [ ] If relevant, you have written a first draft summary describing the change for inclusion in Release Notes. 

## Release Note Draft Snippet

__If relevant, please write a summary of your change that will be suitable for
inclusion in the Release Notes for the next Taquito release.__



Patch:
diff --git a/packages/taquito-rpc/src/taquito-rpc.ts b/packages/taquito-rpc/src/taquito-rpc.ts
index c5a08aafe..c6c342b31 100644
--- a/packages/taquito-rpc/src/taquito-rpc.ts
+++ b/packages/taquito-rpc/src/taquito-rpc.ts
@@ -461,6 +461,8 @@ export class RpcClient implements RpcClientInterface {
       'double_baking_punishment',
       'delay_increment_per_round',
       'tx_rollup_commitment_bond',
+      'vdf_difficulty',
+      'sc_rollup_stake_amount',
     ]);
 
     return {
diff --git a/packages/taquito-rpc/src/types.ts b/packages/taquito-rpc/src/types.ts
index ad370e525..eec9cbb9c 100644
--- a/packages/taquito-rpc/src/types.ts
+++ b/packages/taquito-rpc/src/types.ts
@@ -134,7 +134,7 @@ export interface BlockFullHeader {
   context: string;
   payload_hash?: string;
   payload_round?: number;
-  priority: number;
+  priority?: number;
   proof_of_work_nonce: string;
   seed_nonce_hash?: string;
   liquidity_baking_escape_vote?: boolean | LiquidityBakingToggleVotes;
@@ -1419,6 +1419,7 @@ export interface OperationContentsAndResultMetadataOrigination {
 }
 
 export type ConstantsResponse = ConstantsResponseCommon &
+  ConstantsResponseProto014 &
   ConstantsResponseProto013 &
   ConstantsResponseProto012 &
   ConstantsResponseProto011 &
@@ -1458,6 +1459,27 @@ export interface ConstantsResponseCommon {
 
 export type Ratio = { numerator: number; denominator: number };
 
+export interface DalParametric {
+  feature_enable: boolean;
+  number_of_slots: number;
+  number_of_shards: number;
+  endorsement_lag: number;
+  availability_threshold: number;
+}
+
+export interface ConstantsResponseProto014 extends ConstantsResponseProto013 {
+  max_wrapped_proof_binary_size?: number;
+  nonce_revelation_threshold?: number;
+  vdf_difficulty?: BigNumber;
+  testnet_dictator?: string;
+  dal_parametric?: DalParametric;
+  sc_rollup_stake_amount?: BigNumber;
+  sc_rollup_commitment_period_in_blocks?: number;
+  sc_rollup_max_lookahead_in_blocks?: number;
+  sc_rollup_max_active_outbox_levels?: number;
+  sc_rollup_max_outbox_messages_per_level?: number;
+}
+
 export interface ConstantsResponseProto013
   extends Omit<
     ConstantsResponseProto012,
@@ -1584,7 +1606,11 @@ export interface ContractResponse {
 }
 
 export interface TestChainStatus {
-  status: string;
+  status: 'not_running' | 'forking' | 'running';
+  protocol?: string;
+  expiration?: TimeStampMixed;
+  chain_id?: string;
+  genesis?: string;
 }
 
 export interface MaxOperationListLength {


Test patch:
diff --git a/integration-tests/rpc-get-protocol-constants.spec.ts b/integration-tests/rpc-get-protocol-constants.spec.ts
index f854e9bba..c204e9128 100644
--- a/integration-tests/rpc-get-protocol-constants.spec.ts
+++ b/integration-tests/rpc-get-protocol-constants.spec.ts
@@ -1,11 +1,11 @@
 import { Protocols } from "@taquito/taquito";
 import { CONFIGS } from "./config";
 import BigNumber from 'bignumber.js';
-import { ConstantsResponseCommon, ConstantsResponseProto009, ConstantsResponseProto010, ConstantsResponseProto011, ConstantsResponseProto012, ConstantsResponseProto013 } from "@taquito/rpc";
+import { ConstantsResponseCommon, ConstantsResponseProto009, ConstantsResponseProto010, ConstantsResponseProto011, ConstantsResponseProto012, ConstantsResponseProto013, ConstantsResponseProto014 } from "@taquito/rpc";
 
 CONFIGS().forEach(({ lib, protocol, rpc }) => {
     const Tezos = lib;
-   
+
     const kathmandunet = (protocol === Protocols.PtKathman) ? test : test.skip;
     const jakartanet = (protocol === Protocols.PtJakart2) ? test : test.skip;
     const mondaynet = (protocol === Protocols.ProtoALpha) ? test : test.skip;
@@ -454,6 +454,140 @@ CONFIGS().forEach(({ lib, protocol, rpc }) => {
             });
             done();
         })
+
+        it('successfully fetches Proto12 constants at level 2354016', async (done) => {
+            const constants: ConstantsResponseProto012 & ConstantsResponseCommon = await Tezos.rpc.getConstants({ block: "2354016" });
+
+            expect(constants).toEqual({
+                proof_of_work_nonce_size: 8,
+                nonce_length: 32,
+                max_anon_ops_per_block: 132,
+                max_operation_data_length: 32768,
+                max_proposals_per_delegate: 20,
+                max_micheline_node_count: 50000,
+                max_micheline_bytes_limit: 50000,
+                max_allowed_global_constants_depth: 10000,
+                cache_layout: [new BigNumber(100000000), new BigNumber(240000), new BigNumber(2560)],
+                michelson_maximum_type_size: 2001,
+                preserved_cycles: 5,
+                blocks_per_cycle: 8192,
+                blocks_per_commitment: 64,
+                blocks_per_voting_period: 40960,
+                hard_gas_limit_per_operation: new BigNumber(1040000),
+                hard_gas_limit_per_block: new BigNumber(5200000),
+                proof_of_work_threshold: new BigNumber(70368744177663),
+                tokens_per_roll: new BigNumber(6000000000),
+                seed_nonce_revelation_tip: new BigNumber(125000),
+                origination_size: 257,
+                cost_per_byte: new BigNumber(250),
+                hard_storage_limit_per_operation: new BigNumber(60000),
+                quorum_min: 2000,
+                quorum_max: 7000,
+                min_proposal_quorum: 500,
+                minimal_block_delay: new BigNumber(30),
+                liquidity_baking_subsidy: new BigNumber(2500000),
+                liquidity_baking_sunset_level: 3063809,
+                liquidity_baking_escape_ema_threshold: 666667,
+                blocks_per_stake_snapshot: 512,
+                baking_reward_fixed_portion: new BigNumber("10000000"),
+                baking_reward_bonus_per_slot: new BigNumber(4286),
+                endorsing_reward_per_slot: new BigNumber(2857),
+                max_operations_time_to_live: 120,
+                consensus_committee_size: 7000,
+                consensus_threshold: 4667,
+                minimal_participation_ratio: {
+                    numerator: 2,
+                    denominator: 3
+                },
+                max_slashing_period: 2,
+                frozen_deposits_percentage: 10,
+                double_baking_punishment: new BigNumber(640000000),
+                ratio_of_frozen_deposits_slashed_per_double_endorsement: {
+                    numerator: 1,
+                    denominator: 2
+                },
+                delay_increment_per_round: new BigNumber(15),
+            });
+            done();
+        })
+
+        it('successfully fetches Proto13 constants at level 2656071', async (done) => {
+            const constants: ConstantsResponseProto013 & ConstantsResponseCommon = await Tezos.rpc.getConstants({ block: "2656071" });
+
+            expect(constants).toEqual({
+                proof_of_work_nonce_size: 8,
+                nonce_length: 32,
+                max_anon_ops_per_block: 132,
+                max_operation_data_length: 32768,
+                max_proposals_per_delegate: 20,
+                preserved_cycles: 5,
+                blocks_per_cycle: 8192,
+                blocks_per_commitment: 64,
+                hard_gas_limit_per_operation: new BigNumber(1040000),
+                hard_gas_limit_per_block: new BigNumber(5200000),
+                proof_of_work_threshold: new BigNumber(70368744177663),
+                tokens_per_roll: new BigNumber(6000000000),
+                seed_nonce_revelation_tip: new BigNumber(125000),
+                origination_size: 257,
+                cost_per_byte: new BigNumber(250),
+                hard_storage_limit_per_operation: new BigNumber(60000),
+                quorum_min: 2000,
+                quorum_max: 7000,
+                min_proposal_quorum: 500,
+                liquidity_baking_subsidy: new BigNumber(2500000),
+                liquidity_baking_sunset_level: 3063809,
+                liquidity_baking_toggle_ema_threshold: 1000000000,
+                max_allowed_global_constants_depth: 10000,
+                max_micheline_bytes_limit: 50000,
+                max_micheline_node_count: 50000,
+                michelson_maximum_type_size: 2001,
+                blocks_per_stake_snapshot: 512,
+                baking_reward_fixed_portion: new BigNumber(10000000),
+                baking_reward_bonus_per_slot: new BigNumber(4286),
+                endorsing_reward_per_slot: new BigNumber(2857),
+                max_operations_time_to_live: 120,
+                consensus_committee_size: 7000,
+                consensus_threshold: 4667,
+                minimal_participation_ratio: {
+                    denominator: 3,
+                    numerator: 2,
+                },
+                max_slashing_period: 2,
+                frozen_deposits_percentage: 10,
+                double_baking_punishment: new BigNumber(640000000),
+                ratio_of_frozen_deposits_slashed_per_double_endorsement: {
+                    denominator: 2,
+                    numerator: 1,
+                },
+                minimal_block_delay: new BigNumber(30),
+                delay_increment_per_round: new BigNumber(15),
+                cache_layout_size: 3,
+                cache_sampler_state_cycles: 8,
+                cache_script_size: 100000000,
+                cache_stake_distribution_cycles: 8,
+                cycles_per_voting_period: 5,
+                sc_rollup_challenge_window_in_blocks: 20160,
+                sc_rollup_enable: false,
+                sc_rollup_max_available_messages: 1000000,
+                sc_rollup_origination_size: 6314,
+                tx_rollup_commitment_bond: new BigNumber(10000000000),
+                tx_rollup_cost_per_byte_ema_factor: 120,
+                tx_rollup_enable: true,
+                tx_rollup_finality_period: 40000,
+                tx_rollup_hard_size_limit_per_inbox: 500000,
+                tx_rollup_hard_size_limit_per_message: 5000,
+                tx_rollup_max_commitments_count: 80100,
+                tx_rollup_max_inboxes_count: 40100,
+                tx_rollup_max_messages_per_inbox: 1010,
+                tx_rollup_max_ticket_payload_size: 2048,
+                tx_rollup_max_withdrawals_per_batch: 15,
+                tx_rollup_origination_size: 4000,
+                tx_rollup_rejection_max_proof_size: 30000,
+                tx_rollup_sunset_level: 3473409,
+                tx_rollup_withdraw_period: 40000,
+            });
+            done();
+        })
     })
 
     describe(`Fetch constants for testnet`, () => {
@@ -540,7 +674,7 @@ CONFIGS().forEach(({ lib, protocol, rpc }) => {
 
         kathmandunet(`successfully fetches all constants for kathmandunet using ${rpc}`, async (done) => {
             Tezos.setRpcProvider(rpc);
-            const constants: ConstantsResponseProto013 & ConstantsResponseCommon = await Tezos.rpc.getConstants();
+            const constants: ConstantsResponseProto014 & ConstantsResponseCommon = await Tezos.rpc.getConstants();
             expect(constants).toEqual({
                 proof_of_work_nonce_size: 8,
                 nonce_length: 32,
@@ -590,12 +724,12 @@ CONFIGS().forEach(({ lib, protocol, rpc }) => {
                 },
                 minimal_block_delay: new BigNumber(15),
                 dal_parametric: {
-                        availability_threshold: 50,
-                        endorsement_lag: 1,
-                        feature_enable: false,
-                        number_of_shards: 2048,
-                        number_of_slots: 256,
-                      },
+                    availability_threshold: 50,
+                    endorsement_lag: 1,
+                    feature_enable: false,
+                    number_of_shards: 2048,
+                    number_of_slots: 256,
+                },
                 delay_increment_per_round: new BigNumber(15),
                 cache_layout_size: 3,
                 cache_sampler_state_cycles: 8,
@@ -610,7 +744,7 @@ CONFIGS().forEach(({ lib, protocol, rpc }) => {
                 sc_rollup_max_lookahead_in_blocks: 30000,
                 sc_rollup_max_outbox_messages_per_level: 100,
                 sc_rollup_origination_size: 6314,
-                sc_rollup_stake_amount: "32000000",
+                sc_rollup_stake_amount: new BigNumber("32000000"),
                 tx_rollup_commitment_bond: new BigNumber(10000000000),
                 tx_rollup_cost_per_byte_ema_factor: 120,
                 tx_rollup_enable: true,
@@ -626,7 +760,7 @@ CONFIGS().forEach(({ lib, protocol, rpc }) => {
                 tx_rollup_rejection_max_proof_size: 30000,
                 tx_rollup_sunset_level: 10000000,
                 tx_rollup_withdraw_period: 40000,
-                vdf_difficulty: "8000000000",
+                vdf_difficulty: new BigNumber("8000000000"),
             });
 
             done();
@@ -634,7 +768,7 @@ CONFIGS().forEach(({ lib, protocol, rpc }) => {
 
         mondaynet(`successfully fetches all constants for mondaynet using ${rpc}`, async (done) => {
             Tezos.setRpcProvider(rpc);
-            const constants: ConstantsResponseProto012 & ConstantsResponseCommon = await Tezos.rpc.getConstants();
+            const constants: ConstantsResponseProto014 & ConstantsResponseCommon = await Tezos.rpc.getConstants();
 
             expect(constants).toEqual({
                 proof_of_work_nonce_size: 8,
@@ -690,7 +824,7 @@ CONFIGS().forEach(({ lib, protocol, rpc }) => {
                     feature_enable: false,
                     number_of_shards: 2048,
                     number_of_slots: 256,
-                    },
+                },
                 cache_layout_size: 3,
                 cache_sampler_state_cycles: 8,
                 cache_script_size: 100000000,
diff --git a/packages/taquito-rpc/test/taquito-rpc.spec.ts b/packages/taquito-rpc/test/taquito-rpc.spec.ts
index 3a26f7aac..cd7283bae 100644
--- a/packages/taquito-rpc/test/taquito-rpc.spec.ts
+++ b/packages/taquito-rpc/test/taquito-rpc.spec.ts
@@ -564,6 +564,193 @@ describe('RpcClient test', () => {
     });
   });
 
+  describe('getConstants Proto014', () => {
+    it('query the right url and casts relevant properties to BigNumber', async (done) => {
+      httpBackend.createRequest.mockResolvedValue({
+        proof_of_work_nonce_size: 8,
+        nonce_length: 32,
+        max_anon_ops_per_block: 132,
+        max_operation_data_length: 32768,
+        max_proposals_per_delegate: 20,
+        max_micheline_node_count: 50000,
+        max_micheline_bytes_limit: 50000,
+        max_allowed_global_constants_depth: 10000,
+        cache_layout_size: 3,
+        michelson_maximum_type_size: 2001,
+        max_wrapped_proof_binary_size: 30000,
+        preserved_cycles: 3,
+        blocks_per_cycle: 4096,
+        blocks_per_commitment: 32,
+        nonce_revelation_threshold: 256,
+        blocks_per_stake_snapshot: 256,
+        cycles_per_voting_period: 1,
+        hard_gas_limit_per_operation: '1040000',
+        hard_gas_limit_per_block: '5200000',
+        proof_of_work_threshold: '-1',
+        tokens_per_roll: '6000000000',
+        vdf_difficulty: '8000000000',
+        seed_nonce_revelation_tip: '125000',
+        origination_size: 257,
+        baking_reward_fixed_portion: '10000000',
+        baking_reward_bonus_per_slot: '4286',
+        endorsing_reward_per_slot: '2857',
+        cost_per_byte: '250',
+        hard_storage_limit_per_operation: '60000',
+        quorum_min: 2000,
+        quorum_max: 7000,
+        min_proposal_quorum: 500,
+        liquidity_baking_subsidy: '2500000',
+        liquidity_baking_sunset_level: 10000000,
+        liquidity_baking_toggle_ema_threshold: 1000000000,
+        max_operations_time_to_live: 120,
+        minimal_block_delay: '15',
+        delay_increment_per_round: '15',
+        consensus_committee_size: 7000,
+        consensus_threshold: 4667,
+        minimal_participation_ratio: {
+          numerator: 2,
+          denominator: 3,
+        },
+        max_slashing_period: 2,
+        frozen_deposits_percentage: 10,
+        double_baking_punishment: '640000000',
+        ratio_of_frozen_deposits_slashed_per_double_endorsement: {
+          numerator: 1,
+          denominator: 2,
+        },
+        cache_script_size: 100000000,
+        cache_stake_distribution_cycles: 8,
+        cache_sampler_state_cycles: 8,
+        tx_rollup_enable: true,
+        tx_rollup_origination_size: 4000,
+        tx_rollup_hard_size_limit_per_inbox: 500000,
+        tx_rollup_hard_size_limit_per_message: 5000,
+        tx_rollup_max_withdrawals_per_batch: 15,
+        tx_rollup_commitment_bond: '10000000000',
+        tx_rollup_finality_period: 40000,
+        tx_rollup_withdraw_period: 40000,
+        tx_rollup_max_inboxes_count: 40100,
+        tx_rollup_max_messages_per_inbox: 1010,
+        tx_rollup_max_commitments_count: 80100,
+        tx_rollup_cost_per_byte_ema_factor: 120,
+        tx_rollup_max_ticket_payload_size: 2048,
+        tx_rollup_rejection_max_proof_size: 30000,
+        tx_rollup_sunset_level: 10000000,
+        dal_parametric: {
+          feature_enable: false,
+          number_of_slots: 256,
+          number_of_shards: 2048,
+          endorsement_lag: 1,
+          availability_threshold: 50,
+        },
+        sc_rollup_enable: false,
+        sc_rollup_origination_size: 6314,
+        sc_rollup_challenge_window_in_blocks: 20160,
+        sc_rollup_max_available_messages: 1000000,
+        sc_rollup_stake_amount: '32000000',
+        sc_rollup_commitment_period_in_blocks: 30,
+        sc_rollup_max_lookahead_in_blocks: 30000,
+        sc_rollup_max_active_outbox_levels: 20160,
+        sc_rollup_max_outbox_messages_per_level: 100,
+      });
+
+      const response = await client.getConstants();
+
+      expect(httpBackend.createRequest.mock.calls[0][0]).toEqual({
+        method: 'GET',
+        url: 'root/chains/test/blocks/head/context/constants',
+      });
+      expect(response).toEqual({
+        proof_of_work_nonce_size: 8,
+        nonce_length: 32,
+        max_anon_ops_per_block: 132,
+        max_operation_data_length: 32768,
+        max_proposals_per_delegate: 20,
+        max_micheline_node_count: 50000,
+        max_micheline_bytes_limit: 50000,
+        max_allowed_global_constants_depth: 10000,
+        cache_layout_size: 3,
+        michelson_maximum_type_size: 2001,
+        max_wrapped_proof_binary_size: 30000,
+        preserved_cycles: 3,
+        blocks_per_cycle: 4096,
+        blocks_per_commitment: 32,
+        nonce_revelation_threshold: 256,
+        blocks_per_stake_snapshot: 256,
+        cycles_per_voting_period: 1,
+        hard_gas_limit_per_operation: new BigNumber(1040000),
+        hard_gas_limit_per_block: new BigNumber(5200000),
+        proof_of_work_threshold: new BigNumber(-1),
+        tokens_per_roll: new BigNumber(6000000000),
+        vdf_difficulty: new BigNumber(8000000000),
+        seed_nonce_revelation_tip: new BigNumber(125000),
+        origination_size: 257,
+        baking_reward_fixed_portion: new BigNumber(10000000),
+        baking_reward_bonus_per_slot: new BigNumber(4286),
+        endorsing_reward_per_slot: new BigNumber(2857),
+        cost_per_byte: new BigNumber(250),
+        hard_storage_limit_per_operation: new BigNumber(60000),
+        quorum_min: 2000,
+        quorum_max: 7000,
+        min_proposal_quorum: 500,
+        liquidity_baking_subsidy: new BigNumber(2500000),
+        liquidity_baking_sunset_level: 10000000,
+        liquidity_baking_toggle_ema_threshold: 1000000000,
+        max_operations_time_to_live: 120,
+        minimal_block_delay: new BigNumber(15),
+        delay_increment_per_round: new BigNumber(15),
+        consensus_committee_size: 7000,
+        consensus_threshold: 4667,
+        minimal_participation_ratio: {
+          numerator: 2,
+          denominator: 3,
+        },
+        max_slashing_period: 2,
+        frozen_deposits_percentage: 10,
+        double_baking_punishment: new BigNumber(640000000),
+        ratio_of_frozen_deposits_slashed_per_double_endorsement: {
+          numerator: 1,
+          denominator: 2,
+        },
+        cache_script_size: 100000000,
+        cache_stake_distribution_cycles: 8,
+        cache_sampler_state_cycles: 8,
+        tx_rollup_enable: true,
+        tx_rollup_origination_size: 4000,
+        tx_rollup_hard_size_limit_per_inbox: 500000,
+        tx_rollup_hard_size_limit_per_message: 5000,
+        tx_rollup_max_withdrawals_per_batch: 15,
+        tx_rollup_commitment_bond: new BigNumber(10000000000),
+        tx_rollup_finality_period: 40000,
+        tx_rollup_withdraw_period: 40000,
+        tx_rollup_max_inboxes_count: 40100,
+        tx_rollup_max_messages_per_inbox: 1010,
+        tx_rollup_max_commitments_count: 80100,
+        tx_rollup_cost_per_byte_ema_factor: 120,
+        tx_rollup_max_ticket_payload_size: 2048,
+        tx_rollup_rejection_max_proof_size: 30000,
+        tx_rollup_sunset_level: 10000000,
+        dal_parametric: {
+          feature_enable: false,
+          number_of_slots: 256,
+          number_of_shards: 2048,
+          endorsement_lag: 1,
+          availability_threshold: 50,
+        },
+        sc_rollup_enable: false,
+        sc_rollup_origination_size: 6314,
+        sc_rollup_challenge_window_in_blocks: 20160,
+        sc_rollup_max_available_messages: 1000000,
+        sc_rollup_stake_amount: new BigNumber(32000000),
+        sc_rollup_commitment_period_in_blocks: 30,
+        sc_rollup_max_lookahead_in_blocks: 30000,
+        sc_rollup_max_active_outbox_levels: 20160,
+        sc_rollup_max_outbox_messages_per_level: 100,
+      });
+      done();
+    });
+  });
+
   describe('getConstants Proto012', () => {
     it('query the right url and casts property to BigNumber', async (done) => {
       httpBackend.createRequest.mockReturnValue(