UNPKG

create-tezos-smart-contract

Version:

Node.js toolset to write, test and deploy Tezos smart contracts

70 lines (55 loc) 2.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeTest = void 0; const makeFullTest = (name, contractFile) => (`describe("Testing ${name} contract", () => { const getRandomInt = () => Math.round(Math.random() * 1000); let storage = 0; let contract = null; // Contract will be deployed before every single test, to make sure we // do a proper unit test in a stateless testing process beforeEach(async () => { storage = getRandomInt(); contract = await deployContract('${contractFile}', storage); }); test("it should deploy the contract with correct storage", async () => { // Grab the content of contract's storage in blockchain const contractStorage = await contract.storage(); // In Taquito, numbers are returned as Strings, so we have to wrap result in Number() expect(Number(contractStorage)).toBe(storage); }); test("it should increment the stored number", async () => { const increment = getRandomInt(); // We invoke the "Increment" contract endpoint const op = await contract.methods.increment(increment).send(); await op.confirmation(); // Grab the content of contract's storage in blockchain const contractStorage = await contract.storage(); // In Taquito, numbers are returned as Strings, so we have to wrap result in Number() expect(Number(contractStorage)).toBe(storage + increment); }); test("it should decrement the stored number", async () => { const decrement = getRandomInt(); // We invoke the "Decrement" contract endpoint const op = await contract.methods.decrement(decrement).send(); await op.confirmation(); // Grab the content of contract's storage in blockchain const contractStorage = await contract.storage(); // In Taquito, numbers are returned as Strings, so we have to wrap result in Number() expect(Number(contractStorage)).toBe(storage - decrement); }); }); `); const makeEmptyTest = (name, contractFile) => (`describe("Testing ${name} contract", () => { test("it should deploy the contract with correct storage", async () => { const storage = {}; const contract = await deployContract('${contractFile}', storage); // Grab the content of contract's storage in blockchain const contractStorage = await contract.storage(); expect(Number(contractStorage)).toBe(storage); }); }) `); const makeTest = (name, contractFile, hasExamples) => hasExamples ? makeFullTest(name, contractFile) : makeEmptyTest(name, contractFile); exports.makeTest = makeTest;