refund_query_test.gno
3.22 Kb · 77 lines
1package game_vault
2
3import (
4 "chain"
5 "strconv"
6 "testing"
7
8 "gno.land/p/nt/uassert/v0"
9)
10
11func TestListRefundScopeStates(cur realm, t *testing.T) {
12 vaultTest.Setup(cross(cur), t)
13 vaultTest.CreatePool(cross(cur), "pool:refund-query")
14 processID := vaultTest.CreateParticipationProcess(cross(cur), "process:refund-query", "pool:refund-query", 25)
15
16 states := ListRefundScopeStates(
17 "process:missing", "pool:missing",
18 "process:refund-query", "pool:refund-query",
19 )
20 uassert.Equal(t, 2, len(states))
21 uassert.Equal(t, "0", states[0]["processId"])
22 uassert.Equal(t, "0", states[0]["rewardPoolId"])
23 uassert.Equal(t, strconv.FormatUint(processID, 10), states[1]["processId"])
24 uassert.Equal(t, strconv.Itoa(int(ParticipationProcessStatusOpen)), states[1]["processStatus"])
25 uassert.Equal(t, strconv.Itoa(int(RewardPoolStatusOpen)), states[1]["rewardPoolStatus"])
26}
27
28func TestListParticipationRefundStates(cur realm, t *testing.T) {
29 vaultTest.Setup(cross(cur), t)
30 poolID := vaultTest.CreatePool(cross(cur), "pool:participation-refund-query")
31 processID := vaultTest.CreateParticipationProcess(cross(cur), "process:participation-refund-query", "pool:participation-refund-query", 25)
32 fundID := vaultTest.DepositParticipation(cross(cur), vaultTest.Player1, processID, "participation:1", "payment:1", 25)
33
34 before := ListParticipationRefundStates(
35 strconv.FormatUint(processID, 10), vaultTest.Player1.String(), "payment:1", "refund:1",
36 strconv.FormatUint(processID, 10), vaultTest.Player1.String(), "payment:missing", "refund:missing",
37 )
38 uassert.Equal(t, strconv.FormatUint(fundID, 10), before[0]["fundId"])
39 uassert.Equal(t, strconv.Itoa(int(ParticipationFundStatusHeld)), before[0]["fundEffectiveStatus"])
40 uassert.Equal(t, "false", before[0]["operationProcessed"])
41 uassert.Equal(t, "0", before[1]["fundId"])
42
43 testing.SetOriginCaller(vaultTest.Operator)
44 testing.SetRealm(testing.NewUserRealm(vaultTest.Operator))
45 testing.SetOriginSend(chain.Coins{})
46 RefundParticipationFund(cross(cur), fundID, "refund:1")
47
48 after := ListParticipationRefundStates(
49 strconv.FormatUint(processID, 10), vaultTest.Player1.String(), "payment:1", "refund:1",
50 )
51 uassert.Equal(t, "true", after[0]["fundRefunded"])
52 uassert.Equal(t, "true", after[0]["operationProcessed"])
53 uassert.Equal(t, strconv.FormatUint(poolID, 10), after[0]["refundPoolId"])
54 uassert.Equal(t, "payment:1", after[0]["refundSourceKey"])
55}
56
57func TestRefundStateQueriesRejectMismatchedValues(cur realm, t *testing.T) {
58 uassert.PanicsWithMessage(t, cur, "refund scope key count mismatch", func() {
59 ListRefundScopeStates("process:1")
60 })
61 uassert.PanicsWithMessage(t, cur, "participation refund value count mismatch", func() {
62 ListParticipationRefundStates("1", vaultTest.Player1.String(), "payment:1")
63 })
64
65 scopeKeys := []string{}
66 refundValues := []string{}
67 for index := 0; index <= gameVaultList; index++ {
68 scopeKeys = append(scopeKeys, "process:1", "pool:1")
69 refundValues = append(refundValues, "1", vaultTest.Player1.String(), "payment:1", "refund:1")
70 }
71 uassert.PanicsWithMessage(t, cur, "count exceeds game vault list limit", func() {
72 ListRefundScopeStates(scopeKeys...)
73 })
74 uassert.PanicsWithMessage(t, cur, "count exceeds game vault list limit", func() {
75 ListParticipationRefundStates(refundValues...)
76 })
77}