スマートコントラクトのユニットテストを実行したいので、これは eoslime での初めての体験です。 nodejs の経験はあまりありません。eoslimeのドキュメントをフォローしています:https://docs.eoslime.limechain.tech/examples
eoslime契約ディレクトリにユーザースマートコントラクトファイルを追加しました。 eoslime compile
およびeoslime deploy
コマンドは正常に機能しています。eoslime nodeos
が実行されています。以下は私のテストファイルです:
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 });
});
});
ここで、upsertuser
はマルチインデックステーブルにデータを挿入するアクション名です。テスト中はエラーは発生しません。データがテーブルに保存されていないため、it("Should check user", async () => {
およびit("Should remove user", async () => {
によってエラーが生成されています。abi
ファイルには、次のテーブルが含まれています。
"tables": [
{
"name": "users",
"type": "usertable",
"index_type": "i64",
"key_names": [],
"key_types": []
}
]
私が間違っているところを誰かが助けてくれますか?そして、チェーン上のテーブルデータとトランザクションをチェックする方法は?