Skip to content

Commit

Permalink
Enforcing confirmation in tests (#2847)
Browse files Browse the repository at this point in the history
* test: enforcing confirmation() and adjusted tests to run in ghostnet too

* test: correct a rollup_originate tests
  • Loading branch information
hui-an-yang authored Feb 29, 2024
1 parent 1b21d34 commit 667dc84
Show file tree
Hide file tree
Showing 31 changed files with 72 additions and 46 deletions.
8 changes: 4 additions & 4 deletions integration-tests/__tests__/contract/batch/batch-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ CONFIGS().forEach(({ lib, rpc, setup, knownBaker, createAddress }) => {

it('Verify a batch of transfers and origination operations using a combination of the two notations (array of operation with kind mixed with withTransfer method)', async () => {
/** Tests the usage of a mix of the 2 possible notations for batched operations
* See for details on the 2 notations:
* https://tezostaquito.io/docs/batch_API#--the-array-of-transactions-method
* See for details on the 2 notations:
* https://tezostaquito.io/docs/batch_API#--the-array-of-transactions-method
* https://tezostaquito.io/docs/batch_API#--the-withtransfer-method
*/
const op = await Tezos.batch([
Expand Down Expand Up @@ -101,7 +101,7 @@ CONFIGS().forEach(({ lib, rpc, setup, knownBaker, createAddress }) => {
code: managerCode,
init: { "string": await Tezos.signer.publicKeyHash() },
})

await op.confirmation();
const contract = await op.contract();
expect(op.status).toEqual('applied')

Expand All @@ -124,7 +124,7 @@ CONFIGS().forEach(({ lib, rpc, setup, knownBaker, createAddress }) => {
code: managerCode,
init: { "string": await Tezos.signer.publicKeyHash() },
})

await op.confirmation();
const contract = await op.contract();
expect(op.status).toEqual('applied')

Expand Down
3 changes: 2 additions & 1 deletion integration-tests/__tests__/contract/batch/batch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ CONFIGS().forEach(({ lib, rpc, setup, knownBaker, knownContract, createAddress }
code: managerCode,
init: { string: await Tezos.signer.publicKeyHash() }
});

await op.confirmation();
const contract = await op.contract();
expect(op.status).toEqual('applied');

Expand Down Expand Up @@ -186,6 +186,7 @@ CONFIGS().forEach(({ lib, rpc, setup, knownBaker, knownContract, createAddress }
code: managerCode,
init: { "string": await Tezos.signer.publicKeyHash() },
})
await op.confirmation();
const contract = await op.contract();

const estimateOp = await Tezos.estimate.batch([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CONFIGS().forEach(({ lib, rpc, setup, knownBigMapContract }) => {
const Tezos = lib;
describe(`Test contract origination and accessing big map abstraction by index through contract api using: ${rpc}`, () => {

// In this scenario the code of the contract doesn't have annotation in its storage, so Taquito references element by indexes.
// In this scenario the code of the contract doesn't have annotation in its storage, so Taquito references element by indexes.

beforeEach(async () => {
await setup()
Expand All @@ -19,6 +19,7 @@ CONFIGS().forEach(({ lib, rpc, setup, knownBigMapContract }) => {
code: tokenCode,
init: tokenInit(`${await Tezos.signer.publicKeyHash()}`),
})
await op.confirmation()
const contract = await op.contract()

// Fetch the storage of the newly deployed contract
Expand Down Expand Up @@ -52,6 +53,7 @@ CONFIGS().forEach(({ lib, rpc, setup, knownBigMapContract }) => {
code: tokenCode,
init: tokenInit(`${await Tezos.signer.publicKeyHash()}`),
})
await op.confirmation()
const contract = await op.contract()

// Fetch the storage of the newly deployed contract
Expand Down
9 changes: 6 additions & 3 deletions integration-tests/__tests__/contract/big-map.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CONFIGS().forEach(({ lib, rpc, setup, knownBigMapContract }) => {
const Tezos = lib;

describe(`Test contract origination with initialized Maps with variants of data through contract api using: ${rpc}`, () => {
/** The purpose of the test is to make sure that the keys in the map are properly ordered by Taquito before injection of the operation,
/** The purpose of the test is to make sure that the keys in the map are properly ordered by Taquito before injection of the operation,
* If the keys are not ordered, the node will reject the operation. */

beforeEach(async () => {
Expand Down Expand Up @@ -69,7 +69,7 @@ CONFIGS().forEach(({ lib, rpc, setup, knownBigMapContract }) => {
}),
},
});

await op.confirmation();
await op.contract();
expect(op.hash).toBeDefined();
expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY);
Expand All @@ -95,6 +95,7 @@ CONFIGS().forEach(({ lib, rpc, setup, knownBigMapContract }) => {
3: '3',
},
});
await op.confirmation();
const contract = await op.contract();

interface StorageType {
Expand Down Expand Up @@ -190,6 +191,7 @@ CONFIGS().forEach(({ lib, rpc, setup, knownBigMapContract }) => {
code: tokenCode,
init: tokenInit(`${await Tezos.signer.publicKeyHash()}`),
});
await op.confirmation();
const contract = await op.contract();

// Fetch the storage of the newly deployed contract
Expand Down Expand Up @@ -221,6 +223,7 @@ CONFIGS().forEach(({ lib, rpc, setup, knownBigMapContract }) => {
code: tokenCode,
init: tokenInit(`${await Tezos.signer.publicKeyHash()}`),
});
await op.confirmation();
const contract = await op.contract();

// Fetch the storage of the newly deployed contract
Expand Down Expand Up @@ -252,7 +255,7 @@ CONFIGS().forEach(({ lib, rpc, setup, knownBigMapContract }) => {
3: '3',
},
});

await op.confirmation();
await op.contract();
expect(op.hash).toBeDefined();
expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
code: code,
storage: value
});
await op.confirmation();
const contract = await op.contract();
const contractAbs = await Tezos.contract.at(contract.address);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
code,
storage: 10
});
await opOrigination.confirmation();
const contract = await opOrigination.contract();

// Let's say we want to call the default entry point of the presented contract, and we want to obtain the operation hash before injecting the operation to the node.
// Let's say we want to call the default entry point of the presented contract, and we want to obtain the operation hash before injecting the operation to the node.
// Currently, if we do `await contract.methods.default(5).send()`, we won't be able to obtain the operation hash before the operation gets injected.
// This plan to be addressed in issue #432

Expand All @@ -34,7 +35,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
// We estimate the fees for the operation
const estimate = await Tezos.estimate.transfer(transferParams);

// The createTransferOperation function returns RPCTransferOperation where we include the estimated fees
// The createTransferOperation function returns RPCTransferOperation where we include the estimated fees
const rpcTransferOperation = await createTransferOperation({
...transferParams,
fee: estimate.suggestedFeeMutez,
Expand Down Expand Up @@ -90,5 +91,3 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
}

});


Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
code: depositContractCode,
init: depositContractStorage,
});
await op.confirmation();
const contract = await op.contract();

const operation = await contract.methods.deposit(null).send({ amount: 1 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
code,
storage: 1000000000000000000000000000000000000000000000000000000
});
await op.confirmation();
const contract = await op.contract();

const operation = await contract.methods
Expand All @@ -34,6 +35,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
code,
storage: 1000000000000000000000000000000000000000000000000000000
}).send();
await op.confirmation();
const contract = await op.contract();

const operation = await contract.methods
Expand Down
1 change: 1 addition & 0 deletions integration-tests/__tests__/contract/failwith.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
code: failwithContractCode,
storage: null
})
await op.confirmation()
const contract = await op.contract()
expect(op.hash).toBeDefined();
expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
3: '3'
}
});
await op.confirmation();
const contract = await op.contract();

interface StorageType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {

describe(`Test contract origination of a contract that calls 2nd contract that FAILs through contract api: ${rpc}`, () => {
beforeEach(async () => {
await setup();
await setup();

try {
const op = await Tezos.contract.originate({
balance: "1",
code: failwithContractCode,
storage: null
});

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

opManager = await Tezos.contract.originate({
balance: "1",
code: managerCode,
init: { "string": await Tezos.signer.publicKeyHash() },
});

await opManager.confirmation();
} catch(e) {
console.log(`Error when preparing the test: ${e}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ CONFIGS().forEach(({ lib, rpc, setup, createAddress }) => {
keys: [await account1.signer.publicKey(), await account2.signer.publicKey(), await account3.signer.publicKey()]
}
})
await op2.confirmation();
const contract = await op2.contract();
expect(op2.status).toEqual('applied')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CONFIGS().forEach(({ lib, rpc, setup, createAddress }) => {
keys: [await account1.signer.publicKey(), await account2.signer.publicKey(), await account3.signer.publicKey()]
}
})
await op.confirmation();
const contract = await op.contract();
expect(op.status).toEqual('applied')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CONFIGS().forEach(({ lib, rpc, setup, createAddress, knownContract }) => {
keys: [await account1.signer.publicKey(), await account2.signer.publicKey(), await account3.signer.publicKey()]
}
})
await op.confirmation();
const contract = await op.contract();
expect(op.status).toEqual('applied')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { noAnnotCode, noAnnotInit } from "../../data/token_without_annotation";
CONFIGS().forEach(({ lib, rpc, setup }) => {
const Tezos = lib;
describe(`Test contract origination with no annotations calling methods by index using methodObjects through contract api: ${rpc}`, () => {
/** The goal of the test is to verify a contract entrypoint call using the methodsObject method (contract.methodsObject)
/** The goal of the test is to verify a contract entrypoint call using the methodsObject method (contract.methodsObject)
* in case of a contract having no annotation in its code. */

beforeEach(async () => {
Expand All @@ -29,6 +29,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
code: noAnnotCode,
init: noAnnotInit(await Tezos.signer.publicKeyHash())
})
await op.confirmation()
const contract = await op.contract()

// Make a transfer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
code: noAnnotCode,
init: noAnnotInit(await Tezos.signer.publicKeyHash())
})
await op.confirmation()
const contract = await op.contract()

// Make a transfer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ import { OpKind, TezosToolkit } from "@taquito/taquito";
import { InMemorySigner } from "@taquito/signer";
import { verifySignature } from "@taquito/utils";

CONFIGS().forEach(({ rpc, lib }) => {
CONFIGS().forEach(({ rpc }) => {
const aliceSKey = 'edsk3QoqBuvdamxouPhin7swCvkQNgq4jP5KZPbwWNnwdZpSpJiEbq'

describe(`Test failing_noop through contract api using: ${rpc}`, () => {
let Tezos: TezosToolkit;

beforeAll(async () => {
Tezos = lib;
if(rpc.includes('oxfordnet')){
Tezos = new TezosToolkit('https://rpc.tzkt.io/oxfordnet');
}
if(rpc.includes('ghostnet')){
Tezos = new TezosToolkit('https://rpc.tzkt.io/ghostnet');
}
Tezos.setSignerProvider(new InMemorySigner(aliceSKey));
});

Expand All @@ -37,7 +42,7 @@ CONFIGS().forEach(({ rpc, lib }) => {
let Mainnet: TezosToolkit;

beforeAll(async () => {
Mainnet = new TezosToolkit('https://rpc.tzkt.io/mainnet'); // this is an archive node public rpc url for mainnet
Mainnet = new TezosToolkit('https://rpc.tzkt.io/mainnet'); // this is a mainnet archive history mode public rpc node url
Mainnet.setSignerProvider(new InMemorySigner(aliceSKey));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
});

await op.confirmation();

expect(op.hash).toBeDefined();
expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY);
expect(op.status).toEqual('applied');
expect(op.kernel).toEqual('23212f7573722f62696e2f656e762073680a6578706f7274204b45524e454c3d22303036313733366430313030303030303031323830373630303337663766376630313766363030323766376630313766363030353766376637663766376630313766363030313766303036303031376630313766363030323766376630303630303030303032363130333131373336643631373237343566373236663663366337353730356636333666373236353061373236353631363435663639366537303735373430303030313137333664363137323734356637323666366336633735373035663633366637323635306337373732363937343635356636663735373437303735373430303031313137333664363137323734356637323666366336633735373035663633366637323635306237333734366637323635356637373732363937343635303030323033303530343033303430353036303530333031303030313037313430323033366436353664303230303061366236353732366536353663356637323735366530303036306161343031303432613031303237663431666130303266303130303231303132303030326630313030323130323230303132303032343730343430343165343030343131323431303034316534303034313030313030323161306230623038303032303030343163343030366230623530303130353766343166653030326430303030323130333431666330303266303130303231303232303030326430303030323130343230303032663031303032313035323030313130303432313036323030343230303334363034343032303030343130313661323030313431303136623130303131613035323030353230303234363034343032303030343130373661323030363130303131613062306230623164303130313766343164633031343138343032343139303163313030303231303034313834303232303030313030353431383430323130303330623062333830353030343165343030306231323266366236353732366536353663326636353665373632663732363536323666366637343030343166383030306230323030303130303431666130303062303230303032303034316663303030623032303030303030343166653030306230313031220a');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
code: reduceMap,
storage: [1]
});

await deployContract.confirmation();
const contract = await deployContract.contract();

const op = await contract.methodsObject.default({
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/__tests__/contract/permits.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const create_bytes_to_sign = async (Tezos: TezosToolkit, contractAddress: string
};

const sigParamPacked = packDataBytes(sigParamData, sigParamType);
// signs the hash
// signs the hash
const signature = await Tezos.signer.sign(sigParamPacked.bytes);

return signature.sig
Expand Down Expand Up @@ -314,6 +314,7 @@ CONFIGS().forEach(({ lib, rpc, setup, createAddress }) => {
//Mint 10 tokens to bootstrap 2
const mint_contract = await LocalTez1.contract.at(fa12_contract.address);
const mint = await mint_contract.methods.mint(bootstrap2_address, 10).send();
await mint.confirmation();
expect(mint.hash).toBeDefined();
expect(mint.status).toEqual('applied');
await mint.confirmation();
Expand Down
1 change: 1 addition & 0 deletions integration-tests/__tests__/contract/unit-as-param.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
code: depositContractCode,
init: depositContractStorage
})
await op.confirmation()
const contract = await op.contract()

const operation = await contract.methods.deposit(null).send({ amount: 1, });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
code: singleSaplingStateContractJProtocol(4),
init: '{}'
});

await saplingContractOrigination.confirmation();
saplingContract = await saplingContractOrigination.contract();

const mnemonic1: string = bip39.generateMnemonic();
Expand Down Expand Up @@ -326,4 +326,3 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {

});
});

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ CONFIGS().forEach(({ lib, rpc, setup }) => {
right: SaplingStateValue
}
});

await saplingContractOrigination.confirmation();
saplingContract = await saplingContractOrigination.contract();

// Instantiate an InMemorySpendingKey from a spending key for Alice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CONFIGS().forEach(({ lib, rpc, setup, createAddress }) => {
code: singleSaplingStateContractJProtocol(),
init: '{}'
});

await saplingContractOrigination.confirmation();
saplingContract = await saplingContractOrigination.contract();

// Generate a spending key and an InMemorySpendingKey instance for Bob using a mnemonic
Expand Down Expand Up @@ -139,7 +139,7 @@ CONFIGS().forEach(({ lib, rpc, setup, createAddress }) => {
paymentAddress: alicePaymentAddress,
isSpent: true
},
{ // This input is a payback for when Alice sent 2 tz to bob (3tz - 2tz = 1tz).
{ // This input is a payback for when Alice sent 2 tz to bob (3tz - 2tz = 1tz).
// Alice consumed the 3tz input and received 1tz back.
value: new BigNumber(1000000),
memo: '',
Expand Down Expand Up @@ -262,4 +262,3 @@ CONFIGS().forEach(({ lib, rpc, setup, createAddress }) => {

});
});

Loading

0 comments on commit 667dc84

Please sign in to comment.