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

fix types stdtx #10

Open
wants to merge 1 commit into
base: hub-3-gaia-2-alpha
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions src/types/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -55,7 +61,7 @@ export interface StdTx extends TxValue {

/** @TODO document */
export interface StdFee {
amount: Coin[];
amount: Coin[] | null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you point me to SDK code where StdFee's amount is nullable? I'm not saying it isn't, I'm just not aware of this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your reply. I am currently studying cosmos-sdk. I have not seen that cosmos-sdk has requirements for StdFee 's amount, and I consider that in some business scenarios, there may be no transaction fee.

gas: string;
}

Expand Down
67 changes: 67 additions & 0 deletions test/stdtx.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
});