2013-09-09 20:14:57 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-07-29 00:12:01 +02:00
|
|
|
"reflect"
|
|
|
|
"sort"
|
2014-07-03 13:45:40 +02:00
|
|
|
"testing"
|
|
|
|
|
2013-09-09 20:14:57 +02:00
|
|
|
"github.com/conformal/btcutil"
|
|
|
|
"github.com/conformal/btcwire"
|
|
|
|
)
|
|
|
|
|
2014-07-29 00:12:01 +02:00
|
|
|
func Test_addOutputs(t *testing.T) {
|
|
|
|
msgtx := btcwire.NewMsgTx()
|
|
|
|
pairs := map[string]btcutil.Amount{
|
|
|
|
"1MirQ9bwyQcGVJPwKUgapu5ouK2E2Ey4gX": 10,
|
|
|
|
"12MzCDwodF9G1e7jfwLXfR164RNtx4BRVG": 1,
|
2014-01-16 18:04:47 +01:00
|
|
|
}
|
2014-07-29 00:12:01 +02:00
|
|
|
if err := addOutputs(msgtx, pairs); err != nil {
|
|
|
|
t.Fatal(err)
|
2013-12-04 01:22:47 +01:00
|
|
|
}
|
2014-07-29 00:12:01 +02:00
|
|
|
if len(msgtx.TxOut) != 2 {
|
|
|
|
t.Fatalf("Expected 2 outputs, found only %d", len(msgtx.TxOut))
|
2013-09-09 20:14:57 +02:00
|
|
|
}
|
2014-07-29 00:12:01 +02:00
|
|
|
values := []int{int(msgtx.TxOut[0].Value), int(msgtx.TxOut[1].Value)}
|
|
|
|
sort.Ints(values)
|
|
|
|
if !reflect.DeepEqual(values, []int{1, 10}) {
|
|
|
|
t.Fatalf("Expected values to be [1, 10], got: %v", values)
|
2013-09-09 20:14:57 +02:00
|
|
|
}
|
|
|
|
}
|