Repository: ecadlabs/taquito
Pull request #1006 (2021-08-06 19:21:01)

Added support for the withdrawal of a delegate
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/docs/set_delegate.md b/docs/set_delegate.md
index 255034d01..751ef7ccb 100644
--- a/docs/set_delegate.md
+++ b/docs/set_delegate.md
@@ -67,3 +67,13 @@ const setDelegate = (key: string) => {
   ];
 };
 ```
+
+# How to withdraw delegate
+
+It is possible to `undelegate` by executing a new `setDelegate` operation and not specifying the `delegate` property.
+
+```ts
+// const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL');
+
+await Tezos.contract.setDelegate({ source: 'tz1_source'});
+```
\ No newline at end of file
diff --git a/packages/taquito/src/operations/types.ts b/packages/taquito/src/operations/types.ts
index f2f539a81..38751ecfe 100644
--- a/packages/taquito/src/operations/types.ts
+++ b/packages/taquito/src/operations/types.ts
@@ -194,7 +194,7 @@ export interface ForgedBytes {
  */
 export interface DelegateParams {
   source: string;
-  delegate: string;
+  delegate?: string;
   fee?: number;
   gasLimit?: number;
   storageLimit?: number;
@@ -218,7 +218,7 @@ export interface RPCDelegateOperation {
   fee: number;
   gas_limit: number;
   storage_limit: number;
-  delegate: string;
+  delegate?: string;
 }
 
 /**


Test patch:
diff --git a/integration-tests/contract-set-delegate-auto-estimate.spec.ts b/integration-tests/contract-set-delegate-auto-estimate.spec.ts
index ca456c05f..3a291c5fc 100644
--- a/integration-tests/contract-set-delegate-auto-estimate.spec.ts
+++ b/integration-tests/contract-set-delegate-auto-estimate.spec.ts
@@ -4,7 +4,7 @@ CONFIGS().forEach(({ lib, rpc, setup, knownBaker }) => {
   const Tezos = lib;
   describe(`Test account delegation with estimation using: ${rpc}`, () => {
 
-    beforeEach(async (done) => {
+    beforeAll(async (done) => {
       await setup(true)
       done()
     })
@@ -33,5 +33,19 @@ CONFIGS().forEach(({ lib, rpc, setup, knownBaker }) => {
       }
       done();
     });
+
+    it('withdraw delegate with automatic estimate', async (done) => {
+      const pkh = await Tezos.signer.publicKeyHash();
+      const op = await Tezos.contract.setDelegate({
+        source: pkh,
+      })
+      await op.confirmation()
+      expect(op.hash).toBeDefined();
+      expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY)
+
+      const account = await Tezos.rpc.getDelegate(pkh)
+      expect(account).toBe(null)
+      done();
+    });
   });
 })
diff --git a/integration-tests/rpc-get-protocol-constants.spec.ts b/integration-tests/rpc-get-protocol-constants.spec.ts
index cf0312b16..329e6d023 100644
--- a/integration-tests/rpc-get-protocol-constants.spec.ts
+++ b/integration-tests/rpc-get-protocol-constants.spec.ts
@@ -12,6 +12,7 @@ CONFIGS().forEach(({ lib, protocol, rpc }) => {
 
         const rpcUrl = 'https://api.tez.ie/rpc/mainnet';
         Tezos.setRpcProvider(rpcUrl)
+        // tests
         it('succesfully fails at fetching constants for level 0', async (done) => {
             try {
                 await Tezos.rpc.getConstants({ block: "0" });
@@ -363,7 +364,7 @@ CONFIGS().forEach(({ lib, protocol, rpc }) => {
         })
 
         it('successfully fetches Proto9 constants at level 1480000', async (done) => {
-            const constants: ConstantsResponseProto009 & ConstantsResponseCommon = await Tezos.rpc.getConstants({ block: "1480000" });
+            const constants: ConstantsResponseProto009 & ConstantsResponseCommon = await Tezos.rpc.getConstants();
 
             expect(constants).toEqual({
                 proof_of_work_nonce_size: 8,
@@ -400,48 +401,6 @@ CONFIGS().forEach(({ lib, protocol, rpc }) => {
             });
             done();
         })
-
-        it('successfully fetches Proto10 constants at level 1589492', async (done) => {
-            const constants: ConstantsResponseProto010 & ConstantsResponseCommon = await Tezos.rpc.getConstants({ block: "1589492" });
-
-            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,
-                blocks_per_roll_snapshot: 512,
-                blocks_per_voting_period: 40960,
-                time_between_blocks: [new BigNumber(60), new BigNumber(40)],
-                endorsers_per_block: 256,
-                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(8000000000),
-                michelson_maximum_type_size: 1000,
-                seed_nonce_revelation_tip: new BigNumber(125000),
-                origination_size: 257,
-                block_security_deposit: new BigNumber(640000000),
-                endorsement_security_deposit: new BigNumber(2500000),
-                baking_reward_per_endorsement: [new BigNumber(78125), new BigNumber(11719)],
-                endorsement_reward: [new BigNumber(78125), new BigNumber(52083)],
-                cost_per_byte: new BigNumber(250),
-                hard_storage_limit_per_operation: new BigNumber(60000),
-                quorum_min: 2000,
-                quorum_max: 7000,
-                min_proposal_quorum: 500,
-                initial_endorsers: 192,
-                delay_per_missing_endorsement: new BigNumber(4),
-                minimal_block_delay: new BigNumber(30),
-                liquidity_baking_subsidy: new BigNumber(2500000),
-                liquidity_baking_sunset_level: 2032928,
-                liquidity_baking_escape_ema_threshold: 1000000
-            });
-            done();
-        })
     })
 
     describe(`Fetch constants for testnet`, () => {