Skip to content

Commit

Permalink
Merge pull request #353 from classic-terra/wasm-parity
Browse files Browse the repository at this point in the history
Classic: Parity of WASM Messages
  • Loading branch information
alecande11 authored Jun 12, 2023
2 parents bcff8fb + 956994d commit 036a47f
Show file tree
Hide file tree
Showing 10 changed files with 337 additions and 969 deletions.
138 changes: 40 additions & 98 deletions src/core/wasm/msgs/MsgClearContractAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,132 +19,74 @@ export class MsgClearContractAdmin extends JSONSerializable<

public static fromAmino(
data: MsgClearContractAdmin.Amino,
isClassic?: boolean
_?: boolean
): MsgClearContractAdmin {
if (isClassic) {
const {
value: { admin, contract },
} = data as MsgClearContractAdmin.AminoV1;
return new MsgClearContractAdmin(admin, contract);
} else {
const {
value: { sender, contract },
} = data as MsgClearContractAdmin.AminoV2;
return new MsgClearContractAdmin(sender, contract);
}
const {
value: { sender, contract },
} = data as MsgClearContractAdmin.AminoV2;
return new MsgClearContractAdmin(sender, contract);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public toAmino(isClassic?: boolean): MsgClearContractAdmin.Amino {
public toAmino(_?: boolean): MsgClearContractAdmin.Amino {
const { admin, contract } = this;
if (isClassic) {
return {
type: 'wasm/MsgClearContractAdmin',
value: {
admin,
contract,
},
};
} else {
return {
type: 'wasm/MsgClearAdmin',
value: {
sender: admin,
contract,
},
};
}
return {
type: 'wasm/MsgClearAdmin',
value: {
sender: admin,
contract,
},
};
}

public static fromProto(
data: MsgClearContractAdmin.Proto,
isClassic?: boolean
_?: boolean
): MsgClearContractAdmin {
if (isClassic) {
const { admin, contract } = data as MsgClearContractAdmin.DataV1;
return new MsgClearContractAdmin(admin, contract);
} else {
const { sender, contract } = data as MsgClearContractAdmin.DataV2;
return new MsgClearContractAdmin(sender, contract);
}
const { sender, contract } = data as MsgClearContractAdmin.DataV2;
return new MsgClearContractAdmin(sender, contract);
}

public toProto(isClassic?: boolean): MsgClearContractAdmin.Proto {
if (isClassic) {
return MsgClearContractAdmin_legacy_pb.fromPartial({
admin: this.admin,
contract: this.contract,
});
} else {
return MsgClearAdmin_pb.fromPartial({
sender: this.admin,
contract: this.contract,
});
}
public toProto(_?: boolean): MsgClearContractAdmin.Proto {
return MsgClearAdmin_pb.fromPartial({
sender: this.admin,
contract: this.contract,
});
}

public packAny(isClassic?: boolean): Any {
if (isClassic) {
return Any.fromPartial({
typeUrl: '/terra.wasm.v1beta1.MsgClearContractAdmin',
value: MsgClearContractAdmin_legacy_pb.encode(
this.toProto(isClassic) as MsgClearContractAdmin_legacy_pb
).finish(),
});
} else {
return Any.fromPartial({
typeUrl: '/cosmwasm.wasm.v1.MsgClearAdmin',
value: MsgClearAdmin_pb.encode(
this.toProto(isClassic) as MsgClearAdmin_pb
).finish(),
});
}
return Any.fromPartial({
typeUrl: '/cosmwasm.wasm.v1.MsgClearAdmin',
value: MsgClearAdmin_pb.encode(
this.toProto(isClassic) as MsgClearAdmin_pb
).finish(),
});
}

public static unpackAny(
msgAny: Any,
isClassic?: boolean
): MsgClearContractAdmin {
if (isClassic) {
return MsgClearContractAdmin.fromProto(
MsgClearContractAdmin_legacy_pb.decode(msgAny.value),
isClassic
);
} else {
return MsgClearContractAdmin.fromProto(
MsgClearAdmin_pb.decode(msgAny.value),
isClassic
);
}
return MsgClearContractAdmin.fromProto(
MsgClearAdmin_pb.decode(msgAny.value),
isClassic
);
}

public static fromData(
data: MsgClearContractAdmin.Data,
isClassic?: boolean
_?: boolean
): MsgClearContractAdmin {
if (isClassic) {
const { admin, contract } = data as MsgClearContractAdmin.DataV1;
return new MsgClearContractAdmin(admin, contract);
} else {
const { sender, contract } = data as MsgClearContractAdmin.DataV2;
return new MsgClearContractAdmin(sender, contract);
}
const { sender, contract } = data as MsgClearContractAdmin.DataV2;
return new MsgClearContractAdmin(sender, contract);
}

public toData(isClassic?: boolean): MsgClearContractAdmin.Data {
if (isClassic) {
return {
'@type': '/terra.wasm.v1beta1.MsgClearContractAdmin',
admin: this.admin,
contract: this.contract,
};
} else {
return {
'@type': '/cosmwasm.wasm.v1.MsgClearAdmin',
sender: this.admin,
contract: this.contract,
};
}
public toData(_?: boolean): MsgClearContractAdmin.Data {
return {
'@type': '/cosmwasm.wasm.v1.MsgClearAdmin',
sender: this.admin,
contract: this.contract,
};
}
}

Expand Down
79 changes: 0 additions & 79 deletions src/core/wasm/msgs/MsgExecuteContract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,6 @@ import { MsgExecuteContract as MsgExecuteContract_legacy_pb } from '@classic-ter
import { MsgExecuteContract as MsgExecuteContract_pb } from '@terra-money/terra.proto/cosmwasm/wasm/v1/tx';

describe('MsgExecuteContract', () => {
it('legacy: works when execute_msg is not JSON', () => {
const msg1 = MsgExecuteContract.fromAmino(
{
type: 'wasm/MsgExecuteContract',
value: {
sender: 'terra16xw94u0jgmuaz8zs54xn9x96lxew74gs05gs4h',
contract: 'terra15gwkyepfc6xgca5t5zefzwy42uts8l2m4g40k6',
execute_msg: {
transfer: {
recipient: 'terra13jqgrtqwucx4jdvhg0d4tc80892fscx54298yt',
amount: 10000,
},
},
coins: [],
},
},
true
);

expect(msg1.execute_msg).toMatchObject({
transfer: {
recipient: 'terra13jqgrtqwucx4jdvhg0d4tc80892fscx54298yt',
amount: 10000,
},
});
});

it('works when execute_msg is not JSON', () => {
const msg1 = MsgExecuteContract.fromAmino(
{
Expand Down Expand Up @@ -57,31 +30,6 @@ describe('MsgExecuteContract', () => {
});
});

it('legacy proto', () => {
const msg1 = MsgExecuteContract.fromData(
{
'@type': '/terra.wasm.v1beta1.MsgExecuteContract',
sender: 'terra16xw94u0jgmuaz8zs54xn9x96lxew74gs05gs4h',
contract: 'terra15gwkyepfc6xgca5t5zefzwy42uts8l2m4g40k6',
execute_msg: {
transfer: {
recipient: 'terra13jqgrtqwucx4jdvhg0d4tc80892fscx54298yt',
amount: 10000,
},
},
coins: [],
},
true
);

expect(msg1.execute_msg).toMatchObject({
transfer: {
recipient: 'terra13jqgrtqwucx4jdvhg0d4tc80892fscx54298yt',
amount: 10000,
},
});
});

it('proto', () => {
const msg1 = MsgExecuteContract.fromData(
{
Expand All @@ -107,33 +55,6 @@ describe('MsgExecuteContract', () => {
});
});

it('legacy: with string msg', () => {
const msgWithExecuteString = new MsgExecuteContract(
'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
'execute_msg_as_string',
{ uluna: 120400 }
);
const aminoWithExecuteString = msgWithExecuteString.toAmino(
true
) as MsgExecuteContract.AminoV1;
expect(aminoWithExecuteString.value.execute_msg).toEqual(
msgWithExecuteString.execute_msg
);
const protoWithExecuteString = msgWithExecuteString.toProto(
true
) as MsgExecuteContract_legacy_pb;
expect(protoWithExecuteString.executeMsg.toString()).toEqual(
JSON.stringify(msgWithExecuteString.execute_msg)
);
const dataWithExecuteString = msgWithExecuteString.toData(
true
) as MsgExecuteContract.DataV1;
expect(dataWithExecuteString.execute_msg).toEqual(
msgWithExecuteString.execute_msg
);
});

it('with string msg', () => {
const msgWithExecuteString = new MsgExecuteContract(
'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
Expand Down
Loading

0 comments on commit 036a47f

Please sign in to comment.