def test_stdtx_sign(): """Must match terra-js signature: ```javascript const terra = require('./dist/src/index.js') const mnemonic = "bread genuine element reopen cliff power mean " + "quiz mutual six machine planet dry detect edit slim clap firm " + "jelly success narrow orange echo tomorrow" const masterKey = terra.deriveMasterKeySync(mnemonic) const keypair = terra.deriveKeypair(masterKey) const accAddr = terra.getAccAddress(keypair.publicKey) const msgSend = terra.buildSend( [{ "amount": "1000000", "denom": "uluna" }], "terra18ydtc7jzr07ejkper09rzeysh0qruvfewfk8ch", "terra1ptdx6akgk7wwemlk5j73artt5t6j8am08ql3qv" ); const stdTx = terra.buildStdTx([msgSend], { "gas": "200000", "amount": [ { "amount": "1000", "denom": "uluna" } ] }, "library test") const jsonTx = stdTx.value const txSignature = terra.sign(jsonTx, keypair, { sequence: "0", account_number: "0", chain_id: "columbus-3" }) const signedTx = terra.createSignedTx(stdTx.value, txSignature) console.log(signedTx) ``` """ acc = Account( "bread genuine element reopen cliff power mean quiz mutual six " "machine planet dry detect edit slim clap firm jelly success na" "rrow orange echo tomorrow") send = msg.bank.MsgSend( amount=[msg.Coin(amount="1000000", denom="uluna")], from_address=acc.account_address, to_address="terra1ptdx6akgk7wwemlk5j73artt5t6j8am08ql3qv", ) tx = msg.auth.StdTx( fee=msg.Fee("200000", [msg.Coin("1000", "uluna")]), memo="library test", msg=[send], ) tx.sign_with(acc) assert tx.signatures[0].signature == ( "eIBlrEwWAUUqnBd8W0N4YaNYUS7kKC/EZEtzp9asxOpsb0eifCfZYKxn6" "aiyZ4oJSJhaYV4p1ExyAi6GQLlLJg==") assert tx.signatures[0].pub_key["type"] == "tendermint/PubKeySecp256k1" assert tx.signatures[0].pub_key["value"] == ( "AywvlE/3Tl9A1sAbFxOG06hoyQslxG7Dmj9MBwLU4svG")
def test_stdtx_with_msg_msgsend(): coin_msgsend = msg.Coin(amount="1000", denom="uluna") msgsend = msg.bank.MsgSend(amount=[coin_msgsend], from_address="terra321", to_address="terra123") coin_stdtx = msg.Coin(amount="1000", denom="uluna") fee = msg.Fee(gas="500", amount=[coin_stdtx]) stdtx = msg.auth.StdTx(fee=fee, memo="test", msg=[msgsend], signatures=[]) assert stdtx.msg[0] == msgsend
def test_inout(): out = msg.InOut( address=ADDRESS, coins=[ msg.Coin(amount="1000", denom="uluna"), msg.Coin(amount="40", denom="ukrw"), ], ) assert out.to_json() == json.dumps(OUT, separators=(",", ":"))
def test_msgmultisend(): coin_uluna = msg.Coin(amount="1000", denom="uluna") coin_ukrw = msg.Coin(amount="40", denom="ukrw") value = msg.bank.MsgMultiSend( inputs=[msg.InOut(address=ADDRESS_IN, coins=[coin_uluna, coin_ukrw])], outputs=[ msg.InOut(address=ADDRESS_OUT, coins=[coin_ukrw, coin_uluna ]) # inverted coin order to test sorting ], ) assert value.to_json() == json.dumps(MSG_MULTI_SEND, separators=(",", ":"))
def test_msgsendvalue(): coin = msg.Coin(amount="1000", denom="uluna") value = MsgSendValue(amount=[coin], from_address=ADDRESS_IN, to_address=ADDRESS_OUT) assert value.to_json() == json.dumps(MSG_SEND["value"], separators=(",", ":"))
def test_tx(): acc = Account( "bread genuine element reopen cliff power mean quiz mutual six " "machine planet dry detect edit slim clap firm jelly success na" "rrow orange echo tomorrow" ) send = msg.bank.MsgSend( amount=[msg.Coin(amount="1000000", denom="uluna")], from_address=acc.account_address, to_address=ADDRESS, ) stdtx = msg.auth.StdTx( fee=msg.Fee("200000", [msg.Coin("1000", "uluna")]), memo="library test", msg=[send], ) stdtx.sign_with(acc) tx = msg.Tx( fee=msg.Fee("200000", [msg.Coin("1000", "uluna")]), memo="library test", msg=[send], ) tx.sign_with(acc) assert tx.tx.to_json() == stdtx.to_json()
def test_msgsend(): coin = msg.Coin(amount="1000", denom="uluna") msgsend = msg.bank.MsgSend(amount=[coin], from_address=ADDRESS_IN, to_address=ADDRESS_OUT) assert msgsend.to_json() == json.dumps(MSG_SEND, separators=(",", ":"))
import json from terra import msg from terra.msg.market.msgswap import MsgSwapValue TRADER = "terra1ganslgkvaen5gcqfpxu2fvqa08hxpfzn0ayw2s" COIN = msg.Coin(amount="1000", denom="uluna") ASK_DENOM = "ukrw" MSG_SWAP = { "type": "market/MsgSwap", "value": { "trader": TRADER, "offer_coin": COIN.__dict__, "ask_denom": ASK_DENOM, }, } def test_msgdelegatevalue(): value = MsgSwapValue(trader=TRADER, offer_coin=COIN, ask_denom=ASK_DENOM) assert value.to_json() == json.dumps(MSG_SWAP["value"], separators=(",", ":")) def test_msgdelegate(): msgdelegate = msg.market.MsgSwap(trader=TRADER, offer_coin=COIN, ask_denom=ASK_DENOM) assert msgdelegate.to_json() == json.dumps(MSG_SWAP, separators=(",", ":"))
def test_stdtx(): coin = msg.Coin(amount="1000", denom="uluna") fee = msg.Fee(gas="500", amount=[coin]) stdtx = msg.auth.StdTx(fee=fee, memo="test", msg=[], signatures=[]) assert stdtx.to_json() == json.dumps(STD_TX, separators=(",", ":"))
def test_fee(): amount = msg.Coin(amount="1000", denom="uluna") fee = msg.Fee(gas="500", amount=[amount]) assert fee.to_json() == json.dumps(FEE, separators=(",", ":"))
def test_coin(): amount = msg.Coin(amount="1000", denom="uluna") assert amount.to_json() == json.dumps( FEE["amount"][0], separators=(",", ":") )