cosmos-sdk/types/tx_test.go

67 lines
1.7 KiB
Go
Raw Normal View History

2016-03-20 03:00:43 -07:00
package types
import (
"testing"
2017-02-22 14:30:50 -08:00
cmn "github.com/tendermint/go-common"
"github.com/stretchr/testify/assert"
2016-03-20 03:00:43 -07:00
)
var chainID string = "test_chain"
func TestSendTxSignable(t *testing.T) {
sendTx := &SendTx{
2016-04-01 15:19:07 -07:00
Gas: 222,
Fee: Coin{"", 111},
2016-03-20 03:00:43 -07:00
Inputs: []TxInput{
TxInput{
Address: []byte("input1"),
2016-04-01 15:19:07 -07:00
Coins: Coins{{"", 12345}},
2016-03-20 03:00:43 -07:00
Sequence: 67890,
},
TxInput{
Address: []byte("input2"),
2016-04-01 15:19:07 -07:00
Coins: Coins{{"", 111}},
2016-03-20 03:00:43 -07:00
Sequence: 222,
},
},
Outputs: []TxOutput{
TxOutput{
Address: []byte("output1"),
2016-04-01 15:19:07 -07:00
Coins: Coins{{"", 333}},
2016-03-20 03:00:43 -07:00
},
TxOutput{
Address: []byte("output2"),
2016-04-01 15:19:07 -07:00
Coins: Coins{{"", 444}},
2016-03-20 03:00:43 -07:00
},
},
}
signBytes := sendTx.SignBytes(chainID)
2017-02-22 14:30:50 -08:00
signBytesHex := cmn.Fmt("%X", signBytes)
expected := "010A746573745F636861696E0100000000000000DE00000000000000006F01020106696E7075743101010000000000000030390301093200000106696E70757432010100000000000000006F01DE0000010201076F757470757431010100000000000000014D01076F75747075743201010000000000000001BC"
2017-02-22 14:30:50 -08:00
assert.True(t, signBytesHex == expected,
cmn.Fmt("Got unexpected sign string for SendTx. Expected:\n%v\nGot:\n%v", expected, signBytesHex))
2016-03-20 03:00:43 -07:00
}
2016-03-27 12:47:50 -07:00
func TestAppTxSignable(t *testing.T) {
callTx := &AppTx{
2016-04-01 15:19:07 -07:00
Gas: 222,
Fee: Coin{"", 111},
2017-01-13 16:10:22 -08:00
Name: "X",
2016-03-20 03:00:43 -07:00
Input: TxInput{
Address: []byte("input1"),
2016-04-01 15:19:07 -07:00
Coins: Coins{{"", 12345}},
2016-03-20 03:00:43 -07:00
Sequence: 67890,
},
2016-03-27 12:47:50 -07:00
Data: []byte("data1"),
2016-03-20 03:00:43 -07:00
}
signBytes := callTx.SignBytes(chainID)
2017-02-22 14:30:50 -08:00
signBytesHex := cmn.Fmt("%X", signBytes)
expected := "010A746573745F636861696E0100000000000000DE00000000000000006F0101580106696E70757431010100000000000000303903010932000001056461746131"
2017-02-22 14:30:50 -08:00
assert.True(t, signBytesHex == expected,
cmn.Fmt("Got unexpected sign string for AppTx. Expected:\n%v\nGot:\n%v", expected, signBytesHex))
2016-03-20 03:00:43 -07:00
}