-
Notifications
You must be signed in to change notification settings - Fork 8
/
find_related_accounts_test.go
191 lines (156 loc) · 6.06 KB
/
find_related_accounts_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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package test_main
import (
"fmt"
"testing"
. "github.com/bjartek/overflow"
"github.com/hexops/autogold"
"github.com/stretchr/testify/assert"
)
/*
Tests must be in the same folder as flow.json with contracts and transactions/scripts in subdirectories in order for the path resolver to work correctly
*/
func TestRelatedAccounts(t *testing.T) {
otu := NewOverflowTest(t)
otu.O.Tx("devsetupRelatedAccount",
WithSigner("user1"),
).
AssertSuccess(t)
t.Run("Should be able to get identifier", func(t *testing.T) {
otu.O.Script("devgetRelatedAccountIdentifier",
WithArg("user", "user1"),
WithArg("name", "Blocto"),
WithArg("network", "ETH"),
WithArg("address", "0x1"),
).
AssertWant(t, autogold.Want("ETH_Blocto_0x1", "ETH_Blocto_0x1"))
})
t.Run("Should be able to add wallet", func(t *testing.T) {
otu.addRelatedAccount("user1", "Blocto", "ETH", "0x1")
otu.addRelatedAccount("user1", "Blocto", "ETH", "0x2")
otu.addRelatedAccount("user1", "Blocto", "ETH", "0x4")
otu.addRelatedAccount("user1", "Find", "ETH", "0x3")
otu.addRelatedAccount("user1", "Find", "ETH", "0x5")
})
t.Run("Should be able to add flow wallet", func(t *testing.T) {
otu.addRelatedAccount("user1", "Blocto", "Flow", "user2")
otu.addRelatedAccount("user1", "Blocto", "Flow", "user3")
otu.addRelatedAccount("user1", "Find", "Flow", "find")
})
t.Run("Should be able to get Related wallet in network", func(t *testing.T) {
res := otu.O.Script("devgetRelatedAccounts",
WithArg("user", "user1"),
WithArg("network", "ETH"),
).
AssertWant(t, autogold.Want("devgetRelatedAccounts : ETH", map[string]interface{}{"ETH_Blocto": []interface{}{"0x1", "0x2", "0x4"}, "ETH_Find": []interface{}{"0x3", "0x5"}}))
assert.NoError(t, res.Err)
})
t.Run("Should be able to get Related wallet in Flow", func(t *testing.T) {
res := otu.O.Script("devgetRelatedFlowAccounts",
WithArg("user", "user1"),
).
AssertWant(t, autogold.Want("devgetRelatedFlowAccounts : Flow", map[string]interface{}{"Flow_Blocto": []interface{}{otu.O.Address("user2"), otu.O.Address("user3")}, "Flow_Find": []interface{}{otu.O.Address("find")}}))
assert.NoError(t, res.Err)
})
t.Run("Should be able to get all Related wallet in network", func(t *testing.T) {
res := otu.O.Script("getAllRelatedAccounts",
WithArg("user", "user1"),
).
AssertWant(t, autogold.Want("devgetAllRelatedFlowAccounts", map[string]interface{}{"ETH": map[string]interface{}{"ETH_Blocto": []interface{}{"0x1", "0x2", "0x4"}, "ETH_Find": []interface{}{"0x3", "0x5"}}, "Flow": map[string]interface{}{"Flow_Blocto": []interface{}{otu.O.Address("user2"), otu.O.Address("user3")}, "Flow_Find": []interface{}{otu.O.Address("find")}}}))
assert.NoError(t, res.Err)
})
t.Run("Should be able to update wallet", func(t *testing.T) {
otu.updateRelatedAccount("user1", "Blocto", "ETH", "0x1", "0x1000000")
})
t.Run("Should be able to get updated Related wallet in network", func(t *testing.T) {
res := otu.O.Script("devgetRelatedAccounts",
WithArg("user", "user1"),
WithArg("network", "ETH"),
).
AssertWant(t, autogold.Want("devgetRelatedAccounts : ETH", map[string]interface{}{"ETH_Blocto": []interface{}{"0x2", "0x4", "0x1000000"}, "ETH_Find": []interface{}{"0x3", "0x5"}}))
assert.NoError(t, res.Err)
})
t.Run("Should be able to update flow wallet", func(t *testing.T) {
otu.updateRelatedAccount("user1", "Blocto", "Flow", "user3", "user1")
})
t.Run("Should be able to get updated Related wallet in Flow", func(t *testing.T) {
res := otu.O.Script("devgetRelatedFlowAccounts",
WithArg("user", "user1"),
).
AssertWant(t, autogold.Want("devgetRelatedFlowAccounts : Flow", map[string]interface{}{"Flow_Blocto": []interface{}{otu.O.Address("user2"), otu.O.Address("user1")}, "Flow_Find": []interface{}{otu.O.Address("find")}}))
assert.NoError(t, res.Err)
})
t.Run("Should be able to remove wallet", func(t *testing.T) {
otu.removeRelatedAccount("user1", "Blocto", "ETH", "0x1000000")
})
t.Run("Should be able to get updated Related wallet in network", func(t *testing.T) {
res := otu.O.Script("devgetRelatedAccounts",
WithArg("user", "user1"),
WithArg("network", "ETH"),
).
AssertWant(t, autogold.Want("devgetRelatedAccounts : ETH", map[string]interface{}{"ETH_Blocto": []interface{}{"0x2", "0x4"}, "ETH_Find": []interface{}{"0x3", "0x5"}}))
assert.NoError(t, res.Err)
})
t.Run("Should be able to remove flow wallet", func(t *testing.T) {
otu.removeRelatedAccount("user1", "Blocto", "Flow", "user1")
})
t.Run("Should be able to get updated Related wallet in Flow", func(t *testing.T) {
res := otu.O.Script("devgetRelatedFlowAccounts",
WithArg("user", "user1"),
).
AssertWant(t, autogold.Want("devgetRelatedFlowAccounts : Flow", map[string]interface{}{"Flow_Blocto": []interface{}{otu.O.Address("user2")}, "Flow_Find": []interface{}{otu.O.Address("find")}}))
assert.NoError(t, res.Err)
})
type TestCases struct {
network string
address string
want autogold.Value
}
testCases := []TestCases{
{
network: "Flow",
address: otu.O.Address("user3"),
want: autogold.Want("user3 false", false),
},
{
network: "Flow",
address: otu.O.Address("user1"),
want: autogold.Want("user1 false", false),
},
{
network: "Flow",
address: otu.O.Address("user2"),
want: autogold.Want("user2 true", true),
},
{
network: "ETH",
address: "0x1000000",
want: autogold.Want("0x1000000 false", false),
},
{
network: "ETH",
address: "0x1",
want: autogold.Want("0x1 false", false),
},
{
network: "ETH",
address: "0x2",
want: autogold.Want("0x2 true", true),
},
{
network: "Aptos",
address: "0x1",
want: autogold.Want("Aptos false", false),
},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("Should be able to verify with related accounts on network, testCase : %s", tc.want.Name()), func(t *testing.T) {
res := otu.O.Script("devgetVerifyRelatedAccounts",
WithArg("user", "user1"),
WithArg("network", tc.network),
WithArg("address", tc.address),
).
AssertWant(t, tc.want)
assert.NoError(t, res.Err)
})
}
}