forked from BuxOrg/bux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel_sync_transactions_test.go
103 lines (90 loc) · 2.85 KB
/
model_sync_transactions_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
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
package bux
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestSyncTransaction_GetModelName will test the method GetModelName()
func TestSyncTransaction_GetModelName(t *testing.T) {
t.Parallel()
t.Run("valid name", func(t *testing.T) {
syncTx := newSyncTransaction(testTxID, &SyncConfig{SyncOnChain: true, Broadcast: true}, New())
require.NotNil(t, syncTx)
assert.Equal(t, ModelSyncTransaction.String(), syncTx.GetModelName())
})
t.Run("missing config", func(t *testing.T) {
syncTx := newSyncTransaction(testTxID, nil, New())
require.Nil(t, syncTx)
})
}
func Test_areParentsBroadcast(t *testing.T) {
ctx, client, deferMe := CreateTestSQLiteClient(t, false, true, WithCustomTaskManager(&taskManagerMockBase{}))
defer deferMe()
opts := []ModelOps{WithClient(client)}
tx := newTransaction(testTxHex, append(opts, New())...)
txErr := tx.Save(ctx)
require.NoError(t, txErr)
tx = newTransaction(testTx2Hex, append(opts, New())...)
txErr = tx.Save(ctx)
require.NoError(t, txErr)
tx = newTransaction(testTx3Hex, append(opts, New())...)
txErr = tx.Save(ctx)
require.NoError(t, txErr)
// input of testTxID
syncTx := newSyncTransaction("65bb8d2733298b2d3b441a871868d6323c5392facf0d3eced3a6c6a17dc84c10", &SyncConfig{SyncOnChain: false, Broadcast: false}, append(opts, New())...)
syncTx.BroadcastStatus = SyncStatusComplete
txErr = syncTx.Save(ctx)
require.NoError(t, txErr)
// input of testTxInID
syncTx = newSyncTransaction("89fbccca3a5e2bfc8a161bf7f54e8cb5898e296ae8c23b620b89ed570711f931", &SyncConfig{SyncOnChain: false, Broadcast: false}, append(opts, New())...)
txErr = syncTx.Save(ctx)
require.NoError(t, txErr)
type args struct {
tx *SyncTransaction
opts []ModelOps
}
tests := []struct {
name string
args args
want bool
wantErr assert.ErrorAssertionFunc
}{
{
name: "no parents",
args: args{
tx: newSyncTransaction(testTxID3, &SyncConfig{SyncOnChain: true, Broadcast: true}, New()),
opts: opts,
},
want: true,
wantErr: assert.NoError,
},
{
name: "parent not broadcast",
args: args{
tx: newSyncTransaction(testTxID2, &SyncConfig{SyncOnChain: true, Broadcast: true}, New()),
opts: opts,
},
want: false,
wantErr: assert.NoError,
},
{
name: "parent broadcast",
args: args{
tx: newSyncTransaction(testTxID, &SyncConfig{SyncOnChain: true, Broadcast: true}, New()),
opts: opts,
},
want: true,
wantErr: assert.NoError,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := areParentsBroadcast(ctx, tt.args.tx, tt.args.opts...)
if !tt.wantErr(t, err, fmt.Sprintf("areParentsBroadcast(%v, %v, %v)", ctx, tt.args.tx, tt.args.opts)) {
return
}
assert.Equalf(t, tt.want, got, "areParentsBroadcast(%v, %v, %v)", ctx, tt.args.tx, tt.args.opts)
})
}
}