Repository: ecadlabs/taquito
Pull request #1853 (2022-08-24 23:22:08)

added support for increase paid storage in local forging package
#1766 
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.__


github-actions[bot]: New packages have been deployed to the preview repository at https://npm.preview.tezostaquito.io/.

### Published packages:
```
npm i @taquito/local-forging@13.0.1-43d403db--1853 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/rpc@13.0.1-43d403db--1853 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/signer@13.0.1-43d403db--1853 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/taquito@13.0.1-43d403db--1853 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/remote-signer@13.0.1-43d403db--1853 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/tezbridge-wallet@13.0.1-43d403db--1853 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/michelson-encoder@13.0.1-43d403db--1853 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/contracts-library@13.0.1-43d403db--1853 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/ledger-signer@13.0.1-43d403db--1853 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/beacon-wallet@13.0.1-43d403db--1853 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/http-utils@13.0.1-43d403db--1853 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/tezbridge-signer@13.0.1-43d403db--1853 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/michel-codec@13.0.1-43d403db--1853 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/utils@13.0.1-43d403db--1853 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/tzip12@13.0.1-43d403db--1853 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/tzip16@13.0.1-43d403db--1853 --registry https://npm.preview.tezostaquito.io/
```
<!-- Sticky Pull Request Commentdeploy-packages -->
codecov-commenter: # [Codecov](https://codecov.io/gh/ecadlabs/taquito/pull/1853?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs) Report
> Merging [#1853](https://codecov.io/gh/ecadlabs/taquito/pull/1853?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs) (b715ce5) into [kathmandu](https://codecov.io/gh/ecadlabs/taquito/commit/b3825d40291da2c8124d7d1adf3862726750ef08?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs) (b3825d4) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

```diff
@@              Coverage Diff              @@
##           kathmandu    #1853      +/-   ##
=============================================
+ Coverage      80.75%   80.76%   +0.01%     
=============================================
  Files            205      205              
  Lines          11448    11454       +6     
  Branches        2832     2832              
=============================================
+ Hits            9245     9251       +6     
  Misses          2097     2097              
  Partials         106      106              
```


| [Impacted Files](https://codecov.io/gh/ecadlabs/taquito/pull/1853?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs) | Coverage Δ | |
|---|---|---|
| [packages/taquito-local-forging/src/validator.ts](https://codecov.io/gh/ecadlabs/taquito/pull/1853/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs#diff-cGFja2FnZXMvdGFxdWl0by1sb2NhbC1mb3JnaW5nL3NyYy92YWxpZGF0b3IudHM=) | `100.00% <ø> (ø)` | |
| [packages/taquito-local-forging/src/constants.ts](https://codecov.io/gh/ecadlabs/taquito/pull/1853/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs#diff-cGFja2FnZXMvdGFxdWl0by1sb2NhbC1mb3JnaW5nL3NyYy9jb25zdGFudHMudHM=) | `100.00% <100.00%> (ø)` | |
| [packages/taquito-local-forging/src/decoder.ts](https://codecov.io/gh/ecadlabs/taquito/pull/1853/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs#diff-cGFja2FnZXMvdGFxdWl0by1sb2NhbC1mb3JnaW5nL3NyYy9kZWNvZGVyLnRz) | `94.44% <100.00%> (+0.32%)` | :arrow_up: |
| [packages/taquito-local-forging/src/encoder.ts](https://codecov.io/gh/ecadlabs/taquito/pull/1853/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs#diff-cGFja2FnZXMvdGFxdWl0by1sb2NhbC1mb3JnaW5nL3NyYy9lbmNvZGVyLnRz) | `96.55% <100.00%> (+0.25%)` | :arrow_up: |
| [...ages/taquito-local-forging/src/schema/operation.ts](https://codecov.io/gh/ecadlabs/taquito/pull/1853/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs#diff-cGFja2FnZXMvdGFxdWl0by1sb2NhbC1mb3JnaW5nL3NyYy9zY2hlbWEvb3BlcmF0aW9uLnRz) | `94.28% <100.00%> (+0.08%)` | :arrow_up: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs)


Patch:
diff --git a/packages/taquito-local-forging/src/codec.ts b/packages/taquito-local-forging/src/codec.ts
index 2bd535c42..3413e7738 100644
--- a/packages/taquito-local-forging/src/codec.ts
+++ b/packages/taquito-local-forging/src/codec.ts
@@ -8,6 +8,7 @@ import {
   InvalidKeyHashError,
   InvalidPublicKeyError,
   InvalidAddressError,
+  InvalidContractAddressError,
 } from '@taquito/utils';
 import { OversizedEntryPointError, InvalidBallotValueError, DecodeBallotValueError } from './error';
 import BigNumber from 'bignumber.js';
@@ -194,6 +195,15 @@ export const addressEncoder = (val: string): string => {
   }
 };
 
+export const smartContractAddressEncoder = (val: string): string => {
+  const prefix = val.substring(0, 3);
+
+  if (prefix === Prefix.KT1) {
+    return '01' + prefixEncoder(Prefix.KT1)(val) + '00';
+  }
+  throw new InvalidContractAddressError(val);
+};
+
 export const publicKeyDecoder = (val: Uint8ArrayConsumer) => {
   const preamble = val.consume(1);
   switch (preamble[0]) {
@@ -223,6 +233,16 @@ export const addressDecoder = (val: Uint8ArrayConsumer) => {
   }
 };
 
+export const smartContractAddressDecoder = (val: Uint8ArrayConsumer) => {
+  const preamble = val.consume(1);
+  if (preamble[0] === 0x01) {
+    const scAddress = prefixDecoder(Prefix.KT1)(val);
+    val.consume(1);
+    return scAddress;
+  }
+  throw new InvalidContractAddressError(val.toString());
+};
+
 export const zarithEncoder = (n: string): string => {
   const fn: Array<string> = [];
   let nn = new BigNumber(n, 10);
diff --git a/packages/taquito-local-forging/src/constants.ts b/packages/taquito-local-forging/src/constants.ts
index 0cd9be033..ac1825249 100644
--- a/packages/taquito-local-forging/src/constants.ts
+++ b/packages/taquito-local-forging/src/constants.ts
@@ -25,6 +25,7 @@ export enum CODEC {
   INT16 = 'int16',
   PARAMETERS = 'parameters',
   ADDRESS = 'address',
+  SMART_CONTRACT_ADDRESS = 'smart_contract_address',
   VALUE = 'value',
   MANAGER = 'manager',
   BLOCK_PAYLOAD_HASH = 'blockPayloadHash',
@@ -47,6 +48,7 @@ export enum CODEC {
   TX_ROLLUP_ORIGINATION_PARAM = 'tx_rollup_origination_param',
   TX_ROLLUP_ID = 'tx_rollup_id',
   TX_ROLLUP_BATCH_CONTENT = 'tx_rollup_batch_content',
+  OP_INCREASE_PAID_STORAGE = 'increase_paid_storage',
 }
 
 // See https://tezos.gitlab.io/whitedoc/michelson.html#full-grammar
@@ -228,6 +230,7 @@ export const kindMapping: { [key: number]: string } = {
   0x96: 'tx_rollup_origination',
   0x97: 'tx_rollup_submit_batch',
   0x9e: 'transfer_ticket',
+  0x71: 'increase_paid_storage',
 };
 
 export const kindMappingReverse = (() => {
diff --git a/packages/taquito-local-forging/src/decoder.ts b/packages/taquito-local-forging/src/decoder.ts
index b357f8b88..291eb9ec6 100644
--- a/packages/taquito-local-forging/src/decoder.ts
+++ b/packages/taquito-local-forging/src/decoder.ts
@@ -13,6 +13,7 @@ import {
   proposalDecoder,
   proposalsDecoder,
   publicKeyDecoder,
+  smartContractAddressDecoder,
   txRollupBatchContentDecoder,
   txRollupIdDecoder,
   txRollupOriginationParamDecoder,
@@ -27,6 +28,7 @@ import {
   BallotSchema,
   DelegationSchema,
   EndorsementSchema,
+  IncreasePaidStorageSchema,
   ManagerOperationSchema,
   operationDecoder,
   OriginationSchema,
@@ -61,6 +63,7 @@ export const decoders: { [key: string]: Decoder } = {
   [CODEC.PROPOSAL_ARR]: proposalsDecoder,
   [CODEC.PARAMETERS]: parametersDecoder,
   [CODEC.ADDRESS]: addressDecoder,
+  [CODEC.SMART_CONTRACT_ADDRESS]: smartContractAddressDecoder,
   [CODEC.VALUE]: valueParameterDecoder,
   [CODEC.INT16]: int16Decoder,
   [CODEC.BLOCK_PAYLOAD_HASH]: blockPayloadHashDecoder,
@@ -96,4 +99,6 @@ decoders[CODEC.OP_TX_ROLLUP_ORIGINATION] = (val: Uint8ArrayConsumer) =>
   schemaDecoder(decoders)(TxRollupOriginationSchema)(val);
 decoders[CODEC.OP_TX_ROLLUP_SUBMIT_BATCH] = (val: Uint8ArrayConsumer) =>
   schemaDecoder(decoders)(TxRollupSubmitBatchSchema)(val);
+decoders[CODEC.OP_INCREASE_PAID_STORAGE] = (val: Uint8ArrayConsumer) =>
+  schemaDecoder(decoders)(IncreasePaidStorageSchema)(val);
 decoders[CODEC.MANAGER] = schemaDecoder(decoders)(ManagerOperationSchema);
diff --git a/packages/taquito-local-forging/src/encoder.ts b/packages/taquito-local-forging/src/encoder.ts
index 77b9c9813..146f1d77f 100644
--- a/packages/taquito-local-forging/src/encoder.ts
+++ b/packages/taquito-local-forging/src/encoder.ts
@@ -13,6 +13,7 @@ import {
   proposalEncoder,
   proposalsEncoder,
   publicKeyEncoder,
+  smartContractAddressEncoder,
   txRollupBatchContentEncoder,
   txRollupIdEncoder,
   txRollupOriginationParamEncoder,
@@ -27,6 +28,7 @@ import {
   BallotSchema,
   DelegationSchema,
   EndorsementSchema,
+  IncreasePaidStorageSchema,
   ManagerOperationSchema,
   operationEncoder,
   OriginationSchema,
@@ -59,6 +61,7 @@ export const encoders: { [key: string]: Encoder<any> } = {
   [CODEC.INT32]: int32Encoder,
   [CODEC.PARAMETERS]: parametersEncoder,
   [CODEC.ADDRESS]: addressEncoder,
+  [CODEC.SMART_CONTRACT_ADDRESS]: smartContractAddressEncoder,
   [CODEC.VALUE]: valueParameterEncoder,
   [CODEC.INT16]: int16Encoder,
   [CODEC.BLOCK_PAYLOAD_HASH]: blockPayloadHashEncoder,
@@ -88,4 +91,6 @@ encoders[CODEC.OP_TX_ROLLUP_ORIGINATION] = (val: any) =>
   schemaEncoder(encoders)(TxRollupOriginationSchema)(val);
 encoders[CODEC.OP_TX_ROLLUP_SUBMIT_BATCH] = (val: any) =>
   schemaEncoder(encoders)(TxRollupSubmitBatchSchema)(val);
+encoders[CODEC.OP_INCREASE_PAID_STORAGE] = (val: any) =>
+  schemaEncoder(encoders)(IncreasePaidStorageSchema)(val);
 encoders[CODEC.MANAGER] = schemaEncoder(encoders)(ManagerOperationSchema);
diff --git a/packages/taquito-local-forging/src/schema/operation.ts b/packages/taquito-local-forging/src/schema/operation.ts
index 3473ac91d..f572406e8 100644
--- a/packages/taquito-local-forging/src/schema/operation.ts
+++ b/packages/taquito-local-forging/src/schema/operation.ts
@@ -126,6 +126,16 @@ export const TxRollupSubmitBatchSchema = {
   burn_limit: CODEC.BURN_LIMIT,
 };
 
+export const IncreasePaidStorageSchema = {
+  source: CODEC.PKH,
+  fee: CODEC.ZARITH,
+  counter: CODEC.ZARITH,
+  gas_limit: CODEC.ZARITH,
+  storage_limit: CODEC.ZARITH,
+  amount: CODEC.ZARITH,
+  destination: CODEC.SMART_CONTRACT_ADDRESS,
+};
+
 export const operationEncoder =
   (encoders: { [key: string]: (val: object) => string }) => (operation: { kind: string }) => {
     if (!(operation.kind in encoders) || !(operation.kind in kindMappingReverse)) {
diff --git a/packages/taquito-local-forging/src/validator.ts b/packages/taquito-local-forging/src/validator.ts
index 51c90accd..f80afde7e 100644
--- a/packages/taquito-local-forging/src/validator.ts
+++ b/packages/taquito-local-forging/src/validator.ts
@@ -14,6 +14,7 @@ import {
   TransferTicketSchema,
   TxRollupOriginationSchema,
   TxRollupSubmitBatchSchema,
+  IncreasePaidStorageSchema,
 } from './schema/operation';
 
 type OperationKind =
@@ -29,7 +30,8 @@ type OperationKind =
   | OpKind.REGISTER_GLOBAL_CONSTANT
   | OpKind.TRANSFER_TICKET
   | OpKind.TX_ROLLUP_ORIGINATION
-  | OpKind.TX_ROLLUP_SUBMIT_BATCH;
+  | OpKind.TX_ROLLUP_SUBMIT_BATCH
+  | OpKind.INCREASE_PAID_STORAGE;
 
 const OperationKindMapping = {
   activate_account: ActivationSchema,
@@ -45,6 +47,7 @@ const OperationKindMapping = {
   transfer_ticket: TransferTicketSchema,
   tx_rollup_origination: TxRollupOriginationSchema,
   tx_rollup_submit_batch: TxRollupSubmitBatchSchema,
+  increase_paid_storage: IncreasePaidStorageSchema,
 };
 
 // Asymmetric difference: only account for things in arr2 that are not present in arr1, not vice versa


Test patch:
diff --git a/packages/taquito-local-forging/test/allTestsCases.ts b/packages/taquito-local-forging/test/allTestsCases.ts
index ff338c5ca..ceda865a6 100644
--- a/packages/taquito-local-forging/test/allTestsCases.ts
+++ b/packages/taquito-local-forging/test/allTestsCases.ts
@@ -1414,4 +1414,22 @@ export const kathmanduCases: TestCase[] = [
       ],
     },
   },
+  {
+    name: `Increase Paid Storage operation`,
+    operation: {
+      branch: 'BMV9bffK5yjWCJgUJBsoTRifb4SsAYbkCVwVkKbJHffJYn7ePBL',
+      contents: [
+        {
+          kind: OpKind.INCREASE_PAID_STORAGE,
+          counter: '1',
+          source: 'tz2WH1zahKo2KiS1gcHBhNFTURPfW1Vk7qpE',
+          fee: '100',
+          gas_limit: '10000',
+          storage_limit: '10',
+          amount: '2',
+          destination: 'KT1JHqHQdHSgWBKo6H4UfG8dw3JnZSyjGkHA',
+        },
+      ],
+    },
+  },
 ];