forked from btcsuite/btcwallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreatetx_test_disabled.go
136 lines (124 loc) · 3.15 KB
/
createtx_test_disabled.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// TODO(jrick) Due to the extra encapsulation added during the switch
// to the new txstore, structures can no longer be mocked due to private
// members. Since all members for RecvTxOut and SignedTx are private, the
// simplist solution would be to make RecvTxOut an interface and create
// our own types satisifying the interface for this test package. Until
// then, disable this test.
//
// +build ignore
package main
import (
"testing"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/soapboxsys/ombwallet/tx"
)
func init() {
cfg = &config{
KeypoolSize: 100,
}
}
type allowFreeTest struct {
name string
inputs []*tx.Utxo
curHeight int32
txSize int
free bool
}
var allowFreeTests = []allowFreeTest{
{
name: "priority < 57,600,000",
inputs: []*tx.Utxo{
{
Amt: btcutil.SatoshiPerBitcoin,
Height: 0,
},
},
curHeight: 142, // 143 confirmations
txSize: 250,
free: false,
},
{
name: "priority == 57,600,000",
inputs: []*tx.Utxo{
{
Amt: btcutil.SatoshiPerBitcoin,
Height: 0,
},
},
curHeight: 143, // 144 confirmations
txSize: 250,
free: false,
},
{
name: "priority > 57,600,000",
inputs: []*tx.Utxo{
{
Amt: btcutil.SatoshiPerBitcoin,
Height: 0,
},
},
curHeight: 144, // 145 confirmations
txSize: 250,
free: true,
},
}
func TestAllowFree(t *testing.T) {
for _, test := range allowFreeTests {
calcFree := allowFree(test.curHeight, test.inputs, test.txSize)
if calcFree != test.free {
t.Errorf("Allow free test '%v' failed.", test.name)
}
}
}
func TestFakeTxs(t *testing.T) {
// First we need a wallet.
w, err := keystore.NewStore("banana wallet", "", []byte("banana"),
wire.MainNet, &keystore.BlockStamp{}, 100)
if err != nil {
t.Errorf("Can not create encrypted wallet: %s", err)
return
}
a := &Wallet{
Wallet: w,
lockedOutpoints: map[wire.OutPoint]struct{}{},
}
w.Unlock([]byte("banana"))
// Create and add a fake Utxo so we have some funds to spend.
//
// This will pass validation because txcscript is unaware of invalid
// tx inputs, however, this example would fail in btcd.
utxo := &tx.Utxo{}
addr, err := w.NextChainedAddress(&keystore.BlockStamp{}, 100)
if err != nil {
t.Errorf("Cannot get next address: %s", err)
return
}
copy(utxo.AddrHash[:], addr.ScriptAddress())
ophash := (wire.ShaHash)([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32})
out := wire.NewOutPoint(&ophash, 0)
utxo.Out = tx.OutPoint(*out)
ss, err := txscript.PayToAddrScript(addr)
if err != nil {
t.Errorf("Could not create utxo PkScript: %s", err)
return
}
utxo.Subscript = tx.PkScript(ss)
utxo.Amt = 1000000
utxo.Height = 12345
a.UtxoStore = append(a.UtxoStore, utxo)
// Fake our current block height so btcd doesn't need to be queried.
curBlock.BlockStamp.Height = 12346
// Create the transaction.
pairs := map[string]int64{
"17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": 5000,
}
_, err = a.txToPairs(pairs, 1)
if err != nil {
t.Errorf("Tx creation failed: %s", err)
return
}
}