0

I am about to write some tests to verify some method functionality.

The method functionality is quite simple:

function checkAmount(const store : storage) : storage is
block{
    if Tezos.amount <= store.UserBalance then skip else failwith("Not enought amount.");
} with store

Testmethod:

it("TestCheckAmount", async function() {
    const instance = await Test.deployed();
    
    await assert.rejects(
        instance.checkAmount(),
        (err) => {
            assert.strictEqual(err.message, "Not enought amount.");
            return true;
        },
        "No error is emitted"
    );
  });

Question: How is it possible to manipulate Tezos.amount? This property is always 0tez.

Also I want to cleanup the storage after every tests. I already saw that it is possible to define a afterEach method. But how can I cleanup the storage completely?

const storage = await instance.storage();
//Storage cleanup
storage.Clean()?!?!?

Thanks in advance!!!

0

Question 1: in order to modify the value in Tezos.amount, you must attach an amount in tez to the transaction you send to the smart contract. If you are using Truffle, you are probably using Taquito, in the .send() part of the contract call, add the following parameter: { amount: amountInTez }.

Question 2: I don't understand exactly what a storage cleanup is, there is no "cleanup" or "reset", Truffle deploys a brand new contract for every test, so you start with a clean storage, otherwise the storage updates according to your tests.

5
  • Regarding 1: If i am calling now instance.checkAmount().send({amount: 1000}); the test fails with ".send is not a function". Maybe I imported taquito in a wrong way? I declared it as "require("@taquito/taquito");" – Stiflers Mum Dec 28 '20 at 18:34
  • Regarding 2: I want to describe it a little bit in more detail. I am doing an initial migration with for example Amount = 1000 (Storage is simply an int). At the first test, I just verify if the storage has an Amount of 1000. At the second test I substract 500 from the Amount and verify, if the Amount in Storage is now 500. At the beginning of the third test the storage has still an Amount of 500 (instead of initial 1000). How can I start every tests with the initial data? Before each test I did the deploy as following : instance = await Test.deployed(); – Stiflers Mum Dec 28 '20 at 18:39
  • so it seems to be that all tests are interdependent – Stiflers Mum Dec 28 '20 at 18:40
  • It looks like you are using the built-in Taquito package if you have an instance object, is that correct? In this case, requiring Taquito has no effect in Truffle as Truffle already created an instance of the TezosToolkit. I generally bypass it and import Taquito myself to have access to all its functionalities, you may want to try it in order to attach an amount to the transaction. – Claude Barde Dec 29 '20 at 7:11
  • You are right, the tests are interdependent and each test will use the state of the contract created by the previous tests, you cannot come back to the initial state of the storage, you have to deploy a brand new contract. – Claude Barde Dec 29 '20 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.