This is my first experience with eoslime as I want to do unit testing for smart contracts. Not much experienced with nodejs .I am following eoslime documentation: https://docs.eoslime.limechain.tech/examples
I added user smart contract file in eoslime contracts directory. eoslime compile
and eoslime deploy
commands are going okay. eoslime nodeos
is running. Following is my test file:
const assert = require('assert');
const TOKEN_WASM_PATH = './contracts/user/user.wasm';
const TOKEN_ABI_PATH = './contracts/user/user.abi';
describe("EOSIO User", function (eoslime) {
// Increase mocha(testing framework) time, otherwise tests fails
this.timeout(15000);
let userContract;
let userTable;
let adminAccount;
before(async () => {
adminAccount = await eoslime.Account.load('accname','PK');
});
beforeEach(async () => {
userContract = await eoslime.Contract.deploy(TOKEN_WASM_PATH, TOKEN_ABI_PATH);
userTable = userContract.users;
});
it("Should create a new user", async () => {
await userContract.upsertuser("123","123","123","123","123","123",1, ["grp1"], { from: adminAccount.name });
});
it("Should check user", async () => {
let messages = await userTable.limit(10).find();
messages = await userTable.equal(adminAccount.name).find();
assert.equal(messages.length, 0, "Should not have any rows yet");
const message = messages[0];
assert.equal(message.created_by, adminAccount.name, "account name not correct");
});
it("Should remove user", async () => {
await userContract.eraseuser("123", { from: adminAccount.name });
});
});
Here, upsertuser
is the action name which inserts data in multi-index table. While testing it does not give any error. The error is getting generated by it("Should check user", async () => {
and it("Should remove user", async () => {
because the data is not getting saved in table. The abi
file contains this table:
"tables": [
{
"name": "users",
"type": "usertable",
"index_type": "i64",
"key_names": [],
"key_types": []
}
]
Can anybody help, where I am mistaken? And how to check table data and transactions on chain?