diff --git a/src/types/auth.ts b/src/types/auth.ts index e9eb8476..bb56e762 100644 --- a/src/types/auth.ts +++ b/src/types/auth.ts @@ -46,7 +46,13 @@ export interface DelayedVestingAccount extends AccountValue { } /** @TODO document */ -export interface StdTx extends TxValue { +export interface StdTx { + type: string; + value: StdTxValue; +} + +/** @TODO document */ +export interface StdTxValue extends TxValue { msg: Msg[]; fee: StdFee; signatures: StdSignature[]; @@ -55,7 +61,7 @@ export interface StdTx extends TxValue { /** @TODO document */ export interface StdFee { - amount: Coin[]; + amount: Coin[] | null; gas: string; } diff --git a/test/stdtx.test.ts b/test/stdtx.test.ts new file mode 100644 index 00000000..199e05b8 --- /dev/null +++ b/test/stdtx.test.ts @@ -0,0 +1,67 @@ +import './setup'; +import { base64ToBytes, bytesToBase64 } from '@tendermint/belt'; +import * as Amino from '../'; + +const txData = '2gEoKBapCkOoo2GaChTNi4afLkGQV1Df+AvNv4mvem6PjBIU0kxbneuQG/5QEXWWJm+hoPWFufEaEQoFc3Rha2USCDEwMDAwMDAwEhEKCwoFc3Rha2USAjQwEOa4AhpqCibrWumHIQL9AVlxawWaJcrGJl/aLlLAVxGHlI/BLzj3GC8Zi1a8wRJAummHUrkNaAcMCTg5K7E2SYgLoJA3Rh6MxpxvIcp9LQJ0NPhTCZ1WwuiKhwnKg3R/EU46/GQv7ktmTlPSDjrnCyIQKFNlbnQgdmlhIEx1bmllKQ=='; + +const tx = { + 'type': 'cosmos-sdk/StdTx', + 'value': { + 'msg': [ + { + 'type': 'cosmos-sdk/MsgSend', + 'value': { + 'from_address': 'cosmos1ek9cd8ewgxg9w5xllq9um0uf4aaxaruvcw4v9e', + 'to_address': 'cosmos16fx9h80tjqdlu5q3wktzvmap5r6ctw03myypaq', + 'amount': [ + { + 'denom': 'stake', + 'amount': '10000000' + } + ] + } + } + ], + 'fee': { + 'amount': [ + { + 'denom': 'stake', + 'amount': '40' + } + ], + 'gas': '40038' + }, + 'signatures': [ + { + 'pub_key': { + 'type': 'tendermint/PubKeySecp256k1', + 'value': 'Av0BWXFrBZolysYmX9ouUsBXEYeUj8EvOPcYLxmLVrzB' + }, + 'signature': 'ummHUrkNaAcMCTg5K7E2SYgLoJA3Rh6MxpxvIcp9LQJ0NPhTCZ1WwuiKhwnKg3R/EU46/GQv7ktmTlPSDjrnCw==' + } + ], + 'memo': '(Sent via Lunie)' + } +}; + +describe('StdTx', () => { + describe('decoding', () => { + describe('StdTx', () => { + it('decodes bytes', () => { + const bytes = base64ToBytes(txData); + const value = Amino.unmarshalStdTx(bytes, true); + expect(value).toMatchObject(tx); + }); + }); + }); + + describe('encoding', () => { + describe('StdTx', () => { + it('encodes value', () => { + const bytes = Amino.marshalStdTx(tx, true); + const data = bytesToBase64(bytes); + expect(data).toBe(txData); + }); + }); + }); +});