-
Notifications
You must be signed in to change notification settings - Fork 13
/
transaction_input_test.go
77 lines (62 loc) · 1.85 KB
/
transaction_input_test.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
package mixin
import (
"context"
"testing"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/require"
)
func TestBuildTransaction(t *testing.T) {
ctx := context.Background()
require := require.New(t)
store := newKeystoreFromEnv(t)
dapp, err := NewFromKeystore(&store.Keystore)
require.NoError(err, "init bot client")
t.Run("legacy-network", func(t *testing.T) {
})
t.Run("safe-network", func(t *testing.T) {
utxos, err := dapp.SafeListUtxos(ctx, SafeListUtxoOption{
Members: []string{dapp.ClientID},
Limit: 1,
State: SafeUtxoStateUnspent,
})
require.NoError(err, "SafeListUtxos")
if len(utxos) == 0 {
t.Log("empty unspent utxo")
return
}
b := NewSafeTransactionBuilder(utxos)
b.Memo = "TestSafeMakeTransaction"
tx, err := dapp.MakeTransaction(ctx, b, []*TransactionOutput{
{
Address: RequireNewMixAddress([]string{dapp.ClientID}, 1),
Amount: decimal.New(1, -8),
},
})
require.NoError(err, "MakeTransaction")
raw, err := tx.Dump()
require.NoError(err, "Dump")
t.Log(raw)
request, err := dapp.SafeCreateTransactionRequest(ctx, &SafeTransactionRequestInput{
RequestID: uuidHash([]byte(utxos[0].OutputID + ":SafeCreateTransactionRequest")),
RawTransaction: raw,
})
require.NoError(err, "SafeCreateTransactionRequest")
err = SafeSignTransaction(
tx,
store.SpendKey,
request.Views,
0,
)
require.NoError(err, "SafeSignTransaction")
signedRaw, err := tx.Dump()
require.NoError(err, "tx.Dump")
request1, err := dapp.SafeSubmitTransactionRequest(ctx, &SafeTransactionRequestInput{
RequestID: request.RequestID,
RawTransaction: signedRaw,
})
require.NoError(err, "SafeSubmitTransactionRequest")
_, err = dapp.SafeReadTransactionRequest(ctx, request1.RequestID)
require.NoError(err, "SafeReadTransactionRequest")
t.Log(request1.TransactionHash)
})
}