Repository: ecadlabs/taquito
Pull request #1380 (2022-02-02 16:24:52)

Context clone missing some fields
Fixes Bug: https://github.com/ecadlabs/taquito/issues/1379

---

Before submitting this PR, please make sure:

- [x] 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

FIX Wallet Originated Contract methods usage should work as expected


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

### Published packages:
```
npm i @taquito/contracts-library@11.2.0-3ed49cbd--1380 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/tezbridge-signer@11.2.0-3ed49cbd--1380 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/local-forging@11.2.0-3ed49cbd--1380 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/signer@11.2.0-3ed49cbd--1380 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/rpc@11.2.0-3ed49cbd--1380 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/remote-signer@11.2.0-3ed49cbd--1380 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/tezbridge-wallet@11.2.0-3ed49cbd--1380 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/ledger-signer@11.2.0-3ed49cbd--1380 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/utils@11.2.0-3ed49cbd--1380 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/michel-codec@11.2.0-3ed49cbd--1380 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/tzip12@11.2.0-3ed49cbd--1380 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/http-utils@11.2.0-3ed49cbd--1380 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/beacon-wallet@11.2.0-3ed49cbd--1380 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/michelson-encoder@11.2.0-3ed49cbd--1380 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/taquito@11.2.0-3ed49cbd--1380 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/tzip16@11.2.0-3ed49cbd--1380 --registry https://npm.preview.tezostaquito.io/
```
github-actions[bot]: A new deploy preview is available on Netlify at https://3ed49cbd--tezostaquito.netlify.app
ricklove: Tested this fix, and it does fix the original issue.

Question: is there any side effects (where clone is expected to ignore the last 3 items)?
ricklove: @roxaneletourneau I tried to look for an integration test that covers it. 

The problem seems to be that none of the integration test configs use a cotnext that uses a wallet provider. I'm not sure the best way to create a test that would cover this case:

- Tezos.setWalletProvider
- wallet.originate
- use contract

But it seems that all the wallet integration tests should be using a config that uses this type of setup.
roxaneletourneau: @ricklove 
These 3 parameters should have been included in the clone method, thank you for the fix.

There are integration tests with the contract and others with the wallet API. However, wallet tests depend on the [LegacyWalletProvider](https://github.com/ecadlabs/taquito/blob/11.2.0/packages/taquito/src/wallet/legacy.ts#L11) which in fact fall back to a signer. 



Patch:
diff --git a/docs/wallet_API.md b/docs/wallet_API.md
index 695216c7f..f2540e57f 100644
--- a/docs/wallet_API.md
+++ b/docs/wallet_API.md
@@ -191,11 +191,9 @@ Make sure you have the Beacon browser extension installed (the extension offers
 
 ```js live noInline wallet
 
-//import { BeaconWallet } from '@taquito/beacon-wallet';
-
-
-const options = { name: 'MyAwesomeDapp' };
-const wallet = new BeaconWallet(options);
+// import { BeaconWallet } from '@taquito/beacon-wallet';
+// const options = { name: 'exampleWallet' };
+// const wallet = new BeaconWallet(options);
 
 wallet
   .requestPermissions({ network: { type: 'hangzhounet' } })
diff --git a/packages/taquito/src/context.ts b/packages/taquito/src/context.ts
index 7be048254..c174431c3 100644
--- a/packages/taquito/src/context.ts
+++ b/packages/taquito/src/context.ts
@@ -247,7 +247,10 @@ export class Context {
       this._config,
       this.forger,
       this._injector,
-      this.packer
+      this.packer,
+      this._walletProvider,
+      this._parser,
+      this._globalConstantsProvider,
     );
   }
 
diff --git a/website/src/theme/CodeBlock/index.js b/website/src/theme/CodeBlock/index.js
index a8d61cf20..d732c8b90 100755
--- a/website/src/theme/CodeBlock/index.js
+++ b/website/src/theme/CodeBlock/index.js
@@ -21,7 +21,7 @@ import {
   prefix, 
   Prefix 
 } from '@taquito/utils';
-import {  BeaconWallet } from '@taquito/beacon-wallet';
+import { BeaconWallet } from '@taquito/beacon-wallet';
 import { InMemorySigner, importKey } from '@taquito/signer';
 import { LedgerSigner, DerivationType } from '@taquito/ledger-signer';
 import { TezBridgeWallet } from '@taquito/tezbridge-wallet';
diff --git a/website/versioned_docs/version-11.2.0/wallet_API.md b/website/versioned_docs/version-11.2.0/wallet_API.md
index 695216c7f..f2540e57f 100644
--- a/website/versioned_docs/version-11.2.0/wallet_API.md
+++ b/website/versioned_docs/version-11.2.0/wallet_API.md
@@ -191,11 +191,9 @@ Make sure you have the Beacon browser extension installed (the extension offers
 
 ```js live noInline wallet
 
-//import { BeaconWallet } from '@taquito/beacon-wallet';
-
-
-const options = { name: 'MyAwesomeDapp' };
-const wallet = new BeaconWallet(options);
+// import { BeaconWallet } from '@taquito/beacon-wallet';
+// const options = { name: 'exampleWallet' };
+// const wallet = new BeaconWallet(options);
 
 wallet
   .requestPermissions({ network: { type: 'hangzhounet' } })


Test patch:
diff --git a/packages/taquito/test/context.spec.ts b/packages/taquito/test/context.spec.ts
index ade8c24b7..ed26623fd 100644
--- a/packages/taquito/test/context.spec.ts
+++ b/packages/taquito/test/context.spec.ts
@@ -14,6 +14,39 @@ describe('Configurations for the confirmation methods and streamer', () => {
         context = new Context(mockRpcClient);
     });
 
+    it('Context clone copies all known properties', () => {
+        const cloned = context.clone();
+
+        // Known properties
+        expect(cloned.rpc === context.rpc).toBeTruthy();
+        expect(cloned.signer === context.signer).toBeTruthy();
+        expect(cloned.proto === context.proto).toBeTruthy();
+        expect(cloned.config === context.config).toBeTruthy();
+        expect(cloned.forger === context.forger).toBeTruthy();
+        expect(cloned.injector === context.injector).toBeTruthy();
+        expect(cloned.packer === context.packer).toBeTruthy();
+        expect(cloned.walletProvider === context.walletProvider).toBeTruthy();
+        expect(cloned.parser === context.parser).toBeTruthy();
+        expect(cloned.globalConstantsProvider === context.globalConstantsProvider).toBeTruthy();
+    });
+
+    it('Context clone copies all getter properties', () => {
+        const cloned = context.clone();
+
+        // Check all getter properties (to catch missing properties that might be added in the future)
+        const getterKeys = Object.entries(Object.getOwnPropertyDescriptors(Object.getPrototypeOf(cloned)))
+            .filter(x => !!x[1].get).map(x=>x[0]);
+
+        for(const key of getterKeys){
+            const keyTyped = key as keyof typeof context;
+            try{
+                expect(cloned[keyTyped] === context[keyTyped]).toBeTruthy();
+            } catch {
+                throw new Error(`context.clone did not clone '${key}'`);
+            }
+        }
+    });
+
     it('Context is initialized with default config values except for the confirmationPollingIntervalSecond property', () => {
         expect(context.config.confirmationPollingIntervalSecond).toBeUndefined();
         expect(context.config.confirmationPollingTimeoutSecond).toEqual(180);