From aa1947b696f984aa931f5f029e4a439c45d5e853 Mon Sep 17 00:00:00 2001 From: zj Date: Wed, 26 Aug 2020 17:23:03 +0800 Subject: [PATCH] fix: update amino decode for transfer (#286) --- __tests__/decoder.test.ts | 3 ++- __tests__/fixtures/cancelOrder.json | 2 +- __tests__/fixtures/placeOrder.json | 2 +- __tests__/fixtures/transfer.json | 2 +- __tests__/rpc.test.ts | 9 +++++---- __tests__/transaction.test.ts | 2 +- src/amino/decoder/index.ts | 2 +- src/rpc/index.ts | 1 - src/types/msg/send.ts | 4 +++- 9 files changed, 15 insertions(+), 12 deletions(-) diff --git a/__tests__/decoder.test.ts b/__tests__/decoder.test.ts index 11dc2169..fce5b675 100644 --- a/__tests__/decoder.test.ts +++ b/__tests__/decoder.test.ts @@ -1,5 +1,6 @@ import * as amino from "../src/amino" -import { AminoPrefix } from "../src/types/" +import { unMarshalBinaryLengthPrefixed } from "../src/amino" +import { AminoPrefix, StdTx, SendMsg } from "../src/types/" class Msg { constructor(opts) { diff --git a/__tests__/fixtures/cancelOrder.json b/__tests__/fixtures/cancelOrder.json index 91c0eaa9..328f7bf0 100644 --- a/__tests__/fixtures/cancelOrder.json +++ b/__tests__/fixtures/cancelOrder.json @@ -7,7 +7,7 @@ }, "signMsg": { "account_number": "34", - "chain_id": "Binance-Chain-Nile", + "chain_id": "Binance-Chain-Ganges", "data": null, "memo": "", "msgs": [ diff --git a/__tests__/fixtures/placeOrder.json b/__tests__/fixtures/placeOrder.json index f834434f..928e0e82 100644 --- a/__tests__/fixtures/placeOrder.json +++ b/__tests__/fixtures/placeOrder.json @@ -9,7 +9,7 @@ }, "signMsg": { "account_number": "34", - "chain_id": "Binance-Chain-Nile", + "chain_id": "Binance-Chain-Ganges", "data": null, "memo": "", "msgs": [ diff --git a/__tests__/fixtures/transfer.json b/__tests__/fixtures/transfer.json index 9cef05c6..e4871466 100644 --- a/__tests__/fixtures/transfer.json +++ b/__tests__/fixtures/transfer.json @@ -8,7 +8,7 @@ }, "signMsg": { "account_number": "34", - "chain_id": "Binance-Chain-Nile", + "chain_id": "Binance-Chain-Ganges", "data": null, "memo": "test", "msgs": [ diff --git a/__tests__/rpc.test.ts b/__tests__/rpc.test.ts index 693060cd..77d4dd4a 100644 --- a/__tests__/rpc.test.ts +++ b/__tests__/rpc.test.ts @@ -1,4 +1,4 @@ -import * as rpcClient from "../src/rpc" +import rpcClient from "../src/rpc" const NETWORK = "testnet" const getClient = (type) => { @@ -22,14 +22,14 @@ describe("rpc", () => { const client = getClient("https") const res = await client.status() expect(res).toBeTruthy() - expect(res.node_info.network).toBe("Binance-Chain-Nile") + expect(res.node_info.network).toBe("Binance-Chain-Ganges") }) it("wss status", async () => { const client = getClient("wss") const res = await client.status() expect(res).toBeTruthy() - expect(res.node_info.network).toBe("Binance-Chain-Nile") + expect(res.node_info.network).toBe("Binance-Chain-Ganges") client.close() }) @@ -210,8 +210,9 @@ describe("rpc", () => { it("getTxByHash", async () => { const client = getClient("https") const hashStr = - "2029ED36444DFE12E6A235CFE8B1C81B7F31014D23790E382056B395EC1171FE" + "5E0C54841CF0261EE111EB6B024762DB200F3FA59397967AB4BC641154C0B789" const result = await client.getTxByHash(hashStr, true) + // console.log(JSON.stringify(result)) expect(result).toBeTruthy() expect(result.height).toBeTruthy() expect(result.hash).toBe(hashStr) diff --git a/__tests__/transaction.test.ts b/__tests__/transaction.test.ts index 85bb04d8..894cac11 100644 --- a/__tests__/transaction.test.ts +++ b/__tests__/transaction.test.ts @@ -132,7 +132,7 @@ describe("Transaction", () => { ] const sendMsg = new SendMsg(address, outputs) const data: StdSignMsg = { - chainId: "Binance-Chain-Nile", + chainId: "Binance-Chain-Ganges", accountNumber: accountNumber, sequence: sequence, baseMsg: sendMsg, diff --git a/src/amino/decoder/index.ts b/src/amino/decoder/index.ts index ae6590b0..a7e0ac17 100644 --- a/src/amino/decoder/index.ts +++ b/src/amino/decoder/index.ts @@ -193,7 +193,7 @@ const decodeArrayBinary = (bytes: Buffer, type: any) => { const { offset, val } = decodeBinary(bytes, type, true) arr.push({ ...val }) - bytes = bytes.slice(offset) + bytes = bytes.slice(offset + 1) //add 1 byte of type arrayOffset += offset + 1 diff --git a/src/rpc/index.ts b/src/rpc/index.ts index 12e63f25..843c483e 100644 --- a/src/rpc/index.ts +++ b/src/rpc/index.ts @@ -261,7 +261,6 @@ class RpcClient extends BaseRpc { hash, prove, }) - const txBytes = Buffer.from(res.tx, "base64") const msgAminoPrefix = txBytes.slice(8, 12).toString("hex") const msgType = getMsgByAminoPrefix(msgAminoPrefix) diff --git a/src/types/msg/send.ts b/src/types/msg/send.ts index 0703a7f1..1fe0f4ec 100644 --- a/src/types/msg/send.ts +++ b/src/types/msg/send.ts @@ -94,7 +94,9 @@ export class SendMsg extends BaseMsg { static defaultMsg() { return { inputs: [{ address: Buffer.from(""), coins: [{ denom: "", amount: 0 }] }], - outpus: [{ address: Buffer.from(""), coins: [{ denom: "", amount: 0 }] }], + outputs: [ + { address: Buffer.from(""), coins: [{ denom: "", amount: 0 }] }, + ], aminoPrefix: AminoPrefix.MsgSend, } }