cosmos-sdk/types/tx_test.go

65 lines
1.6 KiB
Go
Raw Normal View History

2016-03-20 03:00:43 -07:00
package types
import (
"testing"
. "github.com/tendermint/go-common"
)
var chainID string = "test_chain"
func TestSendTxSignable(t *testing.T) {
sendTx := &SendTx{
2016-04-01 15:19:07 -07:00
Fee: 111,
Gas: 222,
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)
2016-03-27 12:47:50 -07:00
signBytesHex := Fmt("%X", signBytes)
2016-04-01 15:19:07 -07:00
expected := "010A746573745F636861696E01000000000000006F00000000000000DE01020106696E7075743101010000000000000030390301093200000106696E70757432010100000000000000006F01DE0000010201076F757470757431010100000000000000014D01076F75747075743201010000000000000001BC"
2016-03-27 12:47:50 -07:00
if signBytesHex != expected {
t.Errorf("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
Fee: 111,
Gas: 222,
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)
2016-03-27 12:47:50 -07:00
signBytesHex := Fmt("%X", signBytes)
2017-01-13 16:10:22 -08:00
expected := "010A746573745F636861696E01000000000000006F00000000000000DE0101580106696E70757431010100000000000000303903010932000001056461746131"
2016-03-27 12:47:50 -07:00
if signBytesHex != expected {
t.Errorf("Got unexpected sign string for AppTx. Expected:\n%v\nGot:\n%v", expected, signBytesHex)
2016-03-20 03:00:43 -07:00
}
}