Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MsgInstantiateContract/MsgMigrateContract accepts string msg #247

Merged
merged 1 commit into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/core/wasm/msgs/MsgExecuteContract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,25 @@ describe('MsgExecuteContract', () => {
},
});
});

it('with string msg', () => {
const msgWithExecuteString = new MsgExecuteContract(
'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
'execute_msg_as_string',
{ uluna: 120400 }
);
const aminoWithExecuteString = msgWithExecuteString.toAmino();
expect(aminoWithExecuteString.value.execute_msg).toEqual(
msgWithExecuteString.execute_msg
);
const protoWithExecuteString = msgWithExecuteString.toProto();
expect(protoWithExecuteString.executeMsg.toString()).toEqual(
JSON.stringify(msgWithExecuteString.execute_msg)
);
const dataWithExecuteString = msgWithExecuteString.toData();
expect(dataWithExecuteString.execute_msg).toEqual(
msgWithExecuteString.execute_msg
);
});
});
33 changes: 27 additions & 6 deletions src/core/wasm/msgs/MsgInstantiateContract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,49 @@ const msgWithoutAdmin = new MsgInstantiateContract(
{ uluna: 120400 }
);

const msgWithInitString = new MsgInstantiateContract(
'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
undefined,
1,
'init_msg_as_string',
{ uluna: 120400 }
);

describe('MsgInstantiateContract', () => {
it('amino', () => {
const aminoWithAdmin = msgWithAdmin.toAmino();
expect(aminoWithAdmin.value.admin).toEqual(msgWithAdmin.admin);

const aminoWithoutAmdin = msgWithoutAdmin.toAmino();
expect(aminoWithoutAmdin.value.admin).toEqual(msgWithoutAdmin.admin);
const aminoWithoutAdmin = msgWithoutAdmin.toAmino();
expect(aminoWithoutAdmin.value.admin).toEqual(msgWithoutAdmin.admin);

const aminoWithInitString = msgWithInitString.toAmino();
expect(aminoWithInitString.value.init_msg).toEqual(
msgWithInitString.init_msg
);
});

it('proto', () => {
const protoWithAdmin = msgWithAdmin.toProto();
expect(protoWithAdmin.admin).toEqual(msgWithAdmin.admin);

const protoWithoutAmdin = msgWithoutAdmin.toProto();
expect(protoWithoutAmdin.admin).toEqual('');
const protoWithoutAdmin = msgWithoutAdmin.toProto();
expect(protoWithoutAdmin.admin).toEqual('');

const protoWithInitString = msgWithInitString.toProto();
expect(protoWithInitString.initMsg.toString()).toEqual(
JSON.stringify(msgWithInitString.init_msg)
);
});

it('data', () => {
const dataWithAdmin = msgWithAdmin.toData();
expect(dataWithAdmin.admin).toEqual(msgWithAdmin.admin);

const dataWithoutAmdin = msgWithoutAdmin.toData();
expect(dataWithoutAmdin.admin).toEqual('');
const dataWithoutAdmin = msgWithoutAdmin.toData();
expect(dataWithoutAdmin.admin).toEqual('');

const dataWithInitString = msgWithInitString.toData();
expect(dataWithInitString.init_msg).toEqual(msgWithInitString.init_msg);
});
});
6 changes: 3 additions & 3 deletions src/core/wasm/msgs/MsgInstantiateContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class MsgInstantiateContract extends JSONSerializable<
public sender: AccAddress,
public admin: AccAddress | undefined,
public code_id: number,
public init_msg: object,
public init_msg: object | string,
init_coins: Coins.Input = {}
) {
super();
Expand Down Expand Up @@ -128,7 +128,7 @@ export namespace MsgInstantiateContract {
sender: AccAddress;
admin?: AccAddress;
code_id: string;
init_msg: object;
init_msg: object | string;
init_coins: Coins.Amino;
};
}
Expand All @@ -138,7 +138,7 @@ export namespace MsgInstantiateContract {
sender: AccAddress;
admin: AccAddress;
code_id: string;
init_msg: object;
init_msg: object | string;
init_coins: Coins.Data;
}

Expand Down
47 changes: 47 additions & 0 deletions src/core/wasm/msgs/MsgMigrateContract.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { MsgMigrateContract } from './MsgMigrateContract';

const msgWithAdmin = new MsgMigrateContract(
'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
2,
{ count: 0 }
);

const msgWithMigrateString = new MsgMigrateContract(
'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
2,
'migrate_msg_as_string'
);

describe('MsgMigrateContract', () => {
it('amino', () => {
const aminoWithAdmin = msgWithAdmin.toAmino();
expect(aminoWithAdmin.value.admin).toEqual(msgWithAdmin.admin);

const aminoWithMigrateString = msgWithMigrateString.toAmino();
expect(aminoWithMigrateString.value.migrate_msg).toEqual(
msgWithMigrateString.migrate_msg
);
});

it('proto', () => {
const protoWithAdmin = msgWithAdmin.toProto();
expect(protoWithAdmin.admin).toEqual(msgWithAdmin.admin);

const protoWithMigrateString = msgWithMigrateString.toProto();
expect(protoWithMigrateString.migrateMsg.toString()).toEqual(
JSON.stringify(msgWithMigrateString.migrate_msg)
);
});

it('data', () => {
const dataWithAdmin = msgWithAdmin.toData();
expect(dataWithAdmin.admin).toEqual(msgWithAdmin.admin);

const dataWithMigrateString = msgWithMigrateString.toData();
expect(dataWithMigrateString.migrate_msg).toEqual(
msgWithMigrateString.migrate_msg
);
});
});
6 changes: 3 additions & 3 deletions src/core/wasm/msgs/MsgMigrateContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class MsgMigrateContract extends JSONSerializable<
public admin: AccAddress,
public contract: AccAddress,
public new_code_id: number,
public migrate_msg: object // json object
public migrate_msg: object | string // json object or string
) {
super();
}
Expand Down Expand Up @@ -109,7 +109,7 @@ export namespace MsgMigrateContract {
admin: AccAddress;
contract: AccAddress;
new_code_id: string;
migrate_msg: object;
migrate_msg: object | string;
};
}

Expand All @@ -118,7 +118,7 @@ export namespace MsgMigrateContract {
admin: AccAddress;
contract: AccAddress;
new_code_id: string;
migrate_msg: object;
migrate_msg: object | string;
}

export type Proto = MsgMigrateContract_pb;
Expand Down