diff --git a/integration-tests/contract-drain-delegate-operation.spec.ts b/integration-tests/contract-drain-delegate-operation.spec.ts new file mode 100644 index 0000000000..2757d09530 --- /dev/null +++ b/integration-tests/contract-drain-delegate-operation.spec.ts @@ -0,0 +1,44 @@ +import { TezosToolkit } from "@taquito/taquito"; +import { CONFIGS } from "./config"; + +CONFIGS().forEach(({ lib, rpc, setup, createAddress }) => { + const Tezos = lib; + const flextesanet = (rpc === 'http://0.0.0.0:20000') ? it : it.skip + + describe(`Test drain delegate with defaul consensus key through contract api using: ${rpc}`, () => { + let delegate: TezosToolkit + let delegatePkh: string + let destinationPkh: string + beforeAll(async (done) => { + await setup(true) + + try { + delegate = await createAddress() + delegatePkh = await delegate.signer.publicKeyHash() + const fund = await Tezos.contract.transfer({ amount: 5, to: delegatePkh}) + await fund.confirmation(); + const register = await delegate.contract.registerDelegate({}) + await register.confirmation() + + const destination = await createAddress() + destinationPkh = await destination.signer.publicKeyHash() + const consensus = await delegate.contract.updateConsensusKey({pk: await destination.signer.publicKey()}) + await consensus.confirmation() + } catch(e) { + console.log(JSON.stringify(e)) + } + done(); + }) + flextesanet('Verify that new Account can be created, registered as delegate and drained itself', async (done) => { + + expect((await delegate.rpc.getBalance(delegatePkh)).toNumber()).toBeGreaterThan(0) + await delegate.contract.drainDelegate({ + consensus_key: destinationPkh, + delegate: delegatePkh, + destination: destinationPkh, + }) + expect((await delegate.tz.getBalance(delegatePkh)).toNumber).toEqual(0) + done(); + }); + }); +})