Skip to content

gen

generate kinds of scripts like: test

usage:

gen test

generate typescript test wrappers

example

after gen test, you will get the typescript wrappers for move structs and functions

gen.png

move struct justin_coin_6 will get the following typescript JUSTIN_COIN_6 class

rust
module wasm_test::justin_coin_6 {
    struct JustinCoin6 {}

    fun init_module(sender: &signer) {
        aptos_framework::managed_coin::initialize<JustinCoin6>(
            sender,
            b"Justin Coin",
            b"JST",
            6,
            false,
        );
    }
}
typescript
export class JustinCoin6 implements StructClass {
    $type: string = `${do_get_package_address()}::${MODULE_NAME}::JustinCoin6`;

    dummy_field: boolean;

    constructor(dummy_field: boolean) {
        this.dummy_field = dummy_field;
    }

    into_value() {
        return this.get_value()
    }

    from_bcs_vector_t(bytes: Uint8Array) {
        let args = this.from_bcs_vector(bcs_import.vector(this.get_bcs()).parse(bytes));
        var self = this;
        return args.map(function(arg) {
            arg.$type = self.$type;
            return arg;
        })
    }

    from_bcs_t(bytes: Uint8Array) {
        let result = this.from_bcs(this.get_bcs().parse(bytes));
        result.$type = this.$type;
        return result;
    }

    serialize(arg: any) {
        return this.get_bcs().serialize(arg);
    }

    serialize_bcs() {
        return this.get_bcs()
    }

    return_bcs() {
        return this.get_bcs()
    }

    from_bcs(arg: any) {
        return JustinCoin6.from_bcs(arg)
    }

    from_bcs_vector(args: any) {
        return JustinCoin6.from_bcs_vector(args)
    }

    get_bcs() {
        return JustinCoin6.bcs
    }

    get_value() {
        return this
    }

    static $type() {
        return `${do_get_package_address()}::${MODULE_NAME}::JustinCoin6`
    }

    from(arg: JustinCoin6) {
        this.dummy_field = arg.dummy_field;
    }

    static from_bcs(arg: {
        dummy_field: boolean
    }): JustinCoin6 {
        return new JustinCoin6(arg.dummy_field)
    }

    static from_bcs_vector(args: {
        dummy_field: boolean
    } []): JustinCoin6[] {
        return args.map(function(arg) {
            return new JustinCoin6(arg.dummy_field)
        })
    }

    static get bcs() {
        return bcs_import.struct("JustinCoin6", {
            dummy_field: bcs_import.bool(),
        }).transform({
            input: (val: any) => {
                return val
            },
            output: (val) => new JustinCoin6(val.dummy_field),
        });
    };
}

test functions wrappers

typescript
function init_module(arg0: Signer) {
    let wasm = get_wasm();

    let args: any[] = [
        wasm.new_bytes(Signer.bcs.serialize(arg0).toBytes(), "")
    ]

    wasm.call_return_bcs(PACKAGE_ADDRESS, MODULE_NAME, "init_module", [], args);
}

note

for more information you can visit test wrappers

Released under the MIT License.