Repository: ecadlabs/taquito
Pull request #1052 (2021-09-15 20:06:07)

fix-test-contract-empty-implicit-account-into-a-new-implicit-account.spec.ts
This is a temporary fix. The consumed_gas returned by the RPC 
`helpers/scripts/run_operation` seems too low in this particular case. Thus the `gasLimit` and the `fee` returned by the estimate are too low. See https://gitlab.com/tezos/tezos/-/issues/1754


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/src/contract/estimate.ts b/packages/taquito/src/contract/estimate.ts
index 1d666831f..0a23874e7 100644
--- a/packages/taquito/src/contract/estimate.ts
+++ b/packages/taquito/src/contract/estimate.ts
@@ -52,7 +52,7 @@ export class Estimate {
   constructor(
     private readonly _milligasLimit: number | string,
     private readonly _storageLimit: number | string,
-    private readonly opSize: number | string,
+    public readonly opSize: number | string,
     private readonly minimalFeePerStorageByteMutez: number | string,
     /**
      * @description Base fee in mutez (1 mutez = 1e10−6 tez)


Test patch:
diff --git a/integration-tests/contract-empty-implicit-account-into-new-implicit-account.spec.ts b/integration-tests/contract-empty-implicit-account-into-new-implicit-account.spec.ts
index bdcc0039c..becfd3d1e 100644
--- a/integration-tests/contract-empty-implicit-account-into-new-implicit-account.spec.ts
+++ b/integration-tests/contract-empty-implicit-account-into-new-implicit-account.spec.ts
@@ -9,7 +9,7 @@ CONFIGS().forEach(({ lib, rpc, setup, createAddress }) => {
             await setup()
             done()
         })
-        test('reveals the sender account, creates an unrevealed implicit account, empties the sender account into the created one', 2,  async (done: () => void) => {
+        it('reveals the sender account, creates an unrevealed implicit account, empties the sender account into the created one', async (done) => {
             const receiver = await createAddress();
             const receiver_pkh = await receiver.signer.publicKeyHash();
 
@@ -35,13 +35,21 @@ CONFIGS().forEach(({ lib, rpc, setup, createAddress }) => {
             const totalFees = estimate.suggestedFeeMutez + estimate.burnFeeMutez;
             const maxAmount = balance.minus(totalFees).toNumber();
             
+            // Temporary fix, see https://gitlab.com/tezos/tezos/-/issues/1754
+            // we need to increase the gasLimit and fee returned by the estimation
+            const gasBuffer = 500;
+            const MINIMAL_FEE_PER_GAS_MUTEZ = 0.1;
+            const increasedFee = (gasBuffer: number, opSize: number) => {
+                return (gasBuffer) * MINIMAL_FEE_PER_GAS_MUTEZ + opSize
+            }
+
             const opTransfer = await sender.contract.transfer({
                 to: receiver_pkh,
                 mutez: true,
-                amount: maxAmount,
-                fee: estimate.suggestedFeeMutez,
-                gasLimit: 1900,
-                storageLimit: estimate.storageLimit
+                amount: maxAmount - increasedFee(gasBuffer, Number(estimate.opSize)),
+                fee: estimate.suggestedFeeMutez + increasedFee(gasBuffer, Number(estimate.opSize)), // baker fees
+                gasLimit: estimate.gasLimit + gasBuffer,
+                storageLimit: estimate.storageLimit 
             });
 
             await opTransfer.confirmation();