Skip to content

Commit e01dabc

Browse files
author
James0126
committed
change execute contract message
1 parent b588d0f commit e01dabc

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@terra-money/msg-reader",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Convert common terra.js msg to a sentence",
55
"main": "dist/index.js",
66
"author": "Terra <[email protected]>",

src/index.test.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
MsgDeposit,
99
MsgVote,
1010
MsgMigrateCode,
11+
MsgExecuteContract,
1112
Coin,
1213
Coins,
1314
} = require("@terra-money/terra.js")
@@ -30,7 +31,7 @@ describe("Bank", () => {
3031
test("Send multiple coins", () => {
3132
const msg = new MsgSend(address, recipient, coins)
3233
expect(readMsg(msg)).toBe(
33-
"Send 1000000ukrw, 1000000uluna to terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp"
34+
"Send 1000000ukrw,1000000uluna to terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp"
3435
)
3536
})
3637
})
@@ -87,6 +88,23 @@ describe("Gov", () => {
8788
})
8889
})
8990

91+
describe("Wasm", () => {
92+
const contract = "terra10llyp6v3j3her8u3ce66ragytu45kcmd9asj3u"
93+
test("Execute contract with coins", () => {
94+
const msg = new MsgExecuteContract(address, contract, { send: "" }, [coin])
95+
expect(readMsg(msg)).toBe(
96+
"Execute send on terra10llyp6v3j3her8u3ce66ragytu45kcmd9asj3u with 1000000uluna"
97+
)
98+
})
99+
100+
test("Execute contract without coins", () => {
101+
const msg = new MsgExecuteContract(address, contract, { send: "" })
102+
expect(readMsg(msg)).toBe(
103+
"Execute send on terra10llyp6v3j3her8u3ce66ragytu45kcmd9asj3u"
104+
)
105+
})
106+
})
107+
90108
test("Default", () => {
91109
const msg = new MsgMigrateCode(address, 1, "codes")
92110
expect(readMsg(msg)).toBe("")

src/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ export const readMsg = (msg: Msg) => {
5252

5353
case "wasm/MsgExecuteContract": {
5454
const { contract, execute_msg, coins } = data.value
55-
const key = Object.keys(execute_msg)[0]
56-
return `Execute ${key || "default"} on ${contract} ${
57-
coins && `(-${formatCoins(coins)})`
58-
}`
55+
const [key] = Object.keys(execute_msg)
56+
const payload = key ? ` ${key}` : ""
57+
const suffix = coins.length ? ` with ${formatCoins(coins)}` : ""
58+
59+
return `Execute${payload} on ${contract}${suffix}`
5960
}
6061

6162
default:

0 commit comments

Comments
 (0)