Skip to content

test

when doing unit test in move language, you will have to write [test_only] codes to expose private structs to your move unit test codes. Moreover when you want to know what gas cost for each function, the traditional move unit test can not give you answer.

  • with deepmove wasm based move vm runtime, you can now test move code locally in typescript without writing [test_only] move codes
  • with deepauto framework, the move function bindings are auto generated, therefor you can directly call this bindings functions
  • with test report command, you can get the full gas cost report for each function

here is an example for how to write move unit test in typescript

rust
public fun get(): u8 {
        10
}

public fun get_vec(): (address, String, u8, vector<u16>, MyUrl) {
    let mut v = vector::empty<u16>();
    vector::push_back(&mut v, 10);
    vector::push_back(&mut v, 20);
    (@0x0000000000000000000000000000000089b9f9d1fadc027cf9532d6f99041522, string::utf8(b"JUSTIN_MFT"), 10, v, MyUrl {
        url: string::utf8(b"www.baidu.com")
    })
}
typescript
import { setup, String, U16, U64, U8, new_wasm, beforeTest, afterTest, afterTestAll, get_wasm } from '@deepmove/aptos';
import { afterEach, beforeEach, afterAll, describe, expect, it } from 'vitest';
import { wasm_test } from './wrappers/dependencies/wasm_test/wasm_test';

let package_path = process.cwd();

setup(get_wasm(), package_path);
beforeEach(beforeTest)
afterEach(afterTest)
afterAll(afterTestAll);

describe('wasm_tests', () => {
    it('test get function', () => {
        let [r] = wasm_test.get();

        expect(r).toEqual(10)
    });

    it('test get_vec function', () => {
        let [r1, r2, r3, r4, r5] = wasm_test.get_vec();

        expect(r1).toEqual("0000000000000000000000000000000089b9f9d1fadc027cf9532d6f99041522")
        expect(r2).toEqual("JUSTIN_MFT")
        expect(r3).toEqual(10)
        expect(r4[0]).toEqual(10)
        expect(r4[1]).toEqual(20)
        expect(r5.url).toEqual("www.baidu.com")
    });
});

after writing move unit test codes, you can run test with test command

Released under the MIT License.