Skip to content

Commit

Permalink
fixed flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dsawali committed Nov 30, 2023
1 parent 7e82345 commit 3c5a86e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 34 deletions.
6 changes: 1 addition & 5 deletions integration-tests/contract-deploy-having-ticket.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
const Tezos = lib;

describe(`Test origination of a token contract using: ${rpc}`, () => {

beforeEach(async () => {
await setup();
});
Expand All @@ -19,7 +18,6 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
await op.confirmation();
expect(op.hash).toBeDefined();
expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY);

});

it('Originates a contract having ticket with init in JSON and the contract api', async () => {
Expand All @@ -31,7 +29,6 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
await op.confirmation();
expect(op.hash).toBeDefined();
expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY);

});

it('Originates a contract having ticket with storage and the contract api', async () => {
Expand All @@ -46,7 +43,6 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
await op.confirmation();
expect(op.hash).toBeDefined();
expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY);

});
});
})
});
80 changes: 51 additions & 29 deletions integration-tests/wallet-manager-scenario.spec.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,81 @@
import { CONFIGS } from "./config";
import { managerCode } from "./data/manager_code";
import { MANAGER_LAMBDA } from "@taquito/taquito";
import { CONFIGS } from './config';
import { managerCode } from './data/manager_code';
import { DefaultWalletType, MANAGER_LAMBDA, OriginationWalletOperation } from '@taquito/taquito';

CONFIGS().forEach(({ lib, rpc, setup, knownBaker, knownContract }) => {
const Tezos = lib;

let op: OriginationWalletOperation;
let contract: DefaultWalletType;

describe(`Test TZ Manager through wallet api: ${rpc}`, () => {
beforeEach(async () => {
await setup()
})
test('Verify wallet.transfer scenarios: implicit transfer to and from contracts, set and remove delegate, and transfer from a contract to a contract.', async () => {
const op = await Tezos.wallet.originate({
await setup();

op = await Tezos.wallet.originate({
balance: "1",
code: managerCode,
init: { "string": await Tezos.signer.publicKeyHash() },
}).send();
const contract = await op.contract();
expect(op.status).toBeTruthy

contract = await op.contract();
});

it('Verify wallet.transfer scenarios: implicit transfer to and from contracts, set and remove delegate, and transfer from a contract to a contract.', async () => {
// Transfer from implicit account (tz1) to contract (kt1_alice)
// A regular transfer operation is made. No smart contract calls required for this scenario.
const opTransferToContract = await Tezos.wallet.transfer({ to: contract.address, amount: 0.01 }).send();
await opTransferToContract.confirmation();
expect(op.status).toBeTruthy
const op = await Tezos.wallet.transfer({ to: contract.address, amount: 0.01 }).send();
await op.confirmation();

expect(op.opHash).toBeDefined();
});

it('should be able to transfer from contract to implicit account', async () => {
// Transfer from contract (kt1_alice) to implicit account (tz1)
// We pass a lambda function to the kt1_alice contracts `do` entrypoint. The lambda code causes the contract to transfer
// the specified number (50) of mutez to the target address.
const opTransfer = await contract.methods.do(MANAGER_LAMBDA.transferImplicit("tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh", 5)).send({ amount: 0 })
await opTransfer.confirmation();
expect(opTransfer.status).toBeTruthy
const op = await contract.methods.do(MANAGER_LAMBDA.transferImplicit('tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh', 5)).send({ amount: 0 })
await op.confirmation();

expect(op.opHash).toBeDefined();
});

it('should be able to set delegate from contract', async () => {
// Set delegate on contract kt1_alice by passing a lambda function to kt1_alice's `do` entrypoint
const opSetDelegate = await contract.methods.do(MANAGER_LAMBDA.setDelegate(knownBaker)).send({ amount: 0 })
await opSetDelegate.confirmation();
expect(opSetDelegate.status).toBeTruthy
const op = await contract.methods.do(MANAGER_LAMBDA.setDelegate(knownBaker)).send({ amount: 0 })
await op.confirmation();

expect(op.opHash).toBeDefined();
});

it('should be able to remove delegate from contract', async () => {
// Remove delegate on contract kt1_alice by passing a lambda function to kt1_alice's `do` entrypoint
const removeDelegateOp = await contract.methods.do(MANAGER_LAMBDA.removeDelegate()).send({ amount: 0 })
await removeDelegateOp.confirmation();
expect(removeDelegateOp.status).toBeTruthy
const op = await contract.methods.do(MANAGER_LAMBDA.removeDelegate()).send({ amount: 0 })
await op.confirmation();

const account = await Tezos.rpc.getDelegate(knownBaker)
expect(account).toEqual(knownBaker)
});

it('should be able to transfer from contract to contract', async () => {
// Transfer from contract (kt1_alice) to contract (kt1 bob)
// Notice that we are instructing the kt1_alice contract to send 1 token to kt1_bob. The transfer value is passed to the
// lambda helper function. The transfer amount in the actual transfer operation is 0. We are not transferring the token
// in the transfer operation, we are instructing the contract to transfer the token using the `do` entrypoint of the kt1_alice
// contract.
const transferToContractOp = await contract.methods.do(MANAGER_LAMBDA.transferToContract(knownContract, 1)).send({ amount: 0 })
await transferToContractOp.confirmation();
expect(transferToContractOp.status).toBeTruthy
const op = await contract.methods.do(MANAGER_LAMBDA.transferToContract(knownContract, 1)).send({ amount: 0 })
await op.confirmation();

expect(op.opHash).toBeDefined();
});

it('should throw an error when trying to transfer amount higher than balance', async () => {
try {
await contract.methods.do(MANAGER_LAMBDA.transferImplicit("tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh", 50 * 1000000)).send({ amount: 0 })
fail('Should throw during transfer with amount higher than balance')
const op = await contract.methods.do(MANAGER_LAMBDA.transferImplicit('tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh', 50 * 1000000)).send({ amount: 0 });
await op.confirmation();
} catch (ex: any) {
expect(ex.message).toContain('tez.subtraction_underflow')
expect(ex.message).toContain('tez.subtraction_underflow');
}
})
})
});
});
});

0 comments on commit 3c5a86e

Please sign in to comment.