Skip to content

Commit

Permalink
simple tx signing test
Browse files Browse the repository at this point in the history
  • Loading branch information
solipsis committed Sep 13, 2019
1 parent 1141f09 commit 914025a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions pkg/keepkey/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keepkey
import (
"encoding/hex"
"fmt"
"io/ioutil"
"log"
"os"
"strings"
Expand All @@ -17,7 +18,7 @@ var kks []*Keepkey

// Default device seed for tests
//var testSeed = "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong"
var testSeed = "alcohol woman abuse must during monitor noble actual mixed trade anger aisle"
var testSeed = "alcohol woman abuse must during monitor noble actual mixed trade anger aisle" // TREZOR test seed

// Ethereum root node path
var ethPath = []uint32{0x8000002C, 0x8000003C, 0x80000000, 0x00000000, 0x00000000}
Expand Down Expand Up @@ -49,12 +50,18 @@ func TestParseTx(t *testing.T) {
t.Error(err)
return
}
t.Log("______________________________________________________________--")
t.Logf("%+v\n", tx)
if len(tx.Outputs) != 1 {
t.Error("Transaction did not parse correctly")
}
}

func TestSignTx(t *testing.T) {

SeedDevice()

// tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
// input 0: 0.0039 BTC

phash, _ := hex.DecodeString("d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882")
var prevIndex uint32
inp1 := &kkproto.TxInputType{
Expand All @@ -63,7 +70,6 @@ func TestSignTx(t *testing.T) {
PrevIndex: &prevIndex,
}

//outAddr, _ := hex.DecodeString("1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1")
outAddr := "1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1"

var amt uint64 = 390000 - 10000
Expand All @@ -74,10 +80,15 @@ func TestSignTx(t *testing.T) {
Address: &outAddr,
}

_, err := kk.signTx("BITCOIN", []*kkproto.TxInputType{inp1}, []*kkproto.TxOutputType{out1})
signed, err := kk.signTx("BITCOIN", []*kkproto.TxInputType{inp1}, []*kkproto.TxOutputType{out1})
if err != nil {
t.Fatal(err)
}

expect := "010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b4830450221009a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b7077102202b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede7810121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0160cc0500000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000"
if hex.EncodeToString(signed) != expect {
t.Errorf("Expected: %s, got: %s\n", expect, hex.EncodeToString(signed))
}
}

func TestLoadDevice(t *testing.T) {
Expand Down

0 comments on commit 914025a

Please sign in to comment.