-
Notifications
You must be signed in to change notification settings - Fork 0
/
EMUStakingAdmin_test.go
161 lines (135 loc) · 4.77 KB
/
EMUStakingAdmin_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
package main
import (
"encoding/json"
"fmt"
"testing"
"github.com/bjartek/overflow/overflow"
"github.com/stretchr/testify/assert"
)
// Test Create New Farm
func TestCreateNewFarm(t *testing.T) {
o := overflow.NewTestingEmulator().Start()
setupFUSDVaultWithBalance(o, "account", 1000.0)
flowAmount := 100.0
fusdAmount := 150.0
flowStoragePath := "flowTokenVault"
fusdStoragePath := "fusdVault"
testCreateSwapPool(o, t, flowStoragePath, flowAmount, fusdStoragePath, fusdAmount)
testCreateNewFarm(o, t, 0)
testCreateRewardPool(o, t, "fusdVault", 100.0)
farmMeta := &FarmMeta{}
err := o.ScriptFromFile("/Staking/get_farm_meta").Args(o.Arguments().UInt64(0)).RunMarshalAs(&farmMeta)
if err != nil {
panic(err)
}
assert.Equal(t, farmMeta.Id, json.Number("0"))
assert.Equal(t, farmMeta.TotalStaked, json.Number("0.00000000"))
// assert.Equal(t, farmMeta.Stakes, "")
// assert.Equal(t, farmMeta.RewardTokensPerSecondByID, "")
// /*
// "A.f8d6e0586b0a20c7.StakingRewards.FarmMeta(
// id: 0,
// stakes: {},
// totalStaked: 0.00000000,
// lastRewardTimestamp: 1655367585.00000000,
// farmWeightsByID: {0: 1.00000000, 1: 1.00000000},
// rewardTokensPerSecondByID: {0: 1.00000000, 1: 1.00000000},
// totalAccumulatedTokensPerShareByID: {1: 0.00000000, 0: 0.00000000})")
// */
// no pending rewards
pendingRewards := o.ScriptFromFile("/Staking/get_pending_rewards").Args(o.Arguments().UInt64(0).Account("account")).RunReturnsJsonString() // .RunMarshalAs(&farmMeta)
assert.Equal(t, pendingRewards, string("{}"))
// no Stakes
stakeInfo := o.ScriptFromFile("/Staking/read_stakes_info").Args(o.Arguments().UInt64(0)).RunReturnsJsonString() // .RunMarshalAs(&farmMeta)
assert.Equal(t, stakeInfo, string("{}"))
}
func testCreateNewFarm(o *overflow.Overflow, t *testing.T, farmID uint64) {
FARM_ID := fmt.Sprintf("%d", farmID)
o.TransactionFromFile("/Staking/admin/create_new_farm").SignProposeAndPayAs("account").
Args(o.
Arguments().
UInt64(farmID)).
Test(t).
AssertSuccess().
AssertEmitEvent(overflow.NewTestEvent("A.f8d6e0586b0a20c7.StakingRewards.NewFarmCreated", map[string]interface{}{
"farmID": FARM_ID,
})).
AssertEventCount(1)
}
// Test Create Reward Pool
func TestCreateRewardPool(t *testing.T) {
o := overflow.NewTestingEmulator().Start()
setupFUSDVaultWithBalance(o, "account", 1000.0)
vaultIdentifier := "flowTokenVault"
amount := 100000.0
testCreateRewardPool(o, t, vaultIdentifier, amount)
}
func testCreateRewardPool(o *overflow.Overflow, t *testing.T,
vaultIdentifier string,
amount float64) {
nftsAccepted := []string{} // []string{"ExampleNFTCollection", "ExampleNFT2Collection"}
signer := "account"
EVENT_EXPECTED := storagePathToTokenIdentifier(vaultIdentifier)
AMOUNT_EXPECTED := float64ToUFix64String(amount)
SIGNER_ADDRESS := "0x" + o.Account(signer).Address().String()
o.ScriptFromFile("")
o.TransactionFromFile("/Staking/admin/create_reward_pool").SignProposeAndPayAs(signer).
Args(o.
Arguments().
String(vaultIdentifier).
UFix64(amount).
StringArray(nftsAccepted...)).
Test(t).
AssertSuccess().
AssertEmitEvent(overflow.NewTestEvent(EVENT_EXPECTED+".TokensWithdrawn", map[string]interface{}{
"amount": AMOUNT_EXPECTED,
"from": SIGNER_ADDRESS,
})).
AssertEmitEvent(overflow.NewTestEvent("A.f8d6e0586b0a20c7.StakingRewards.RewardPoolCreated", map[string]interface{}{
"id": "1",
})).
AssertEventCount(2)
}
// Test update mocktimestamp
func TestUpdateMockTimestamp(t *testing.T) {
o := overflow.NewTestingEmulator().Start()
setupFUSDVaultWithBalance(o, "account", 1000.0)
updateMockTimestamp(o, t, 100.0)
}
func updateMockTimestamp(o *overflow.Overflow, t *testing.T, delta float64) {
o.TransactionFromFile("/Staking/admin/update_mock_timestamp").SignProposeAndPayAs("account").
Args(o.
Arguments().
UFix64(delta)).
Test(t).
AssertSuccess()
}
func TestToggleMockTime(t *testing.T) {
o := overflow.NewTestingEmulator().Start()
setupFUSDVaultWithBalance(o, "account", 1000.0)
toggleMockTime(o, t)
updateMockTimestamp(o, t, 100.0)
}
func toggleMockTime(o *overflow.Overflow, t *testing.T) {
o.TransactionFromFile("/Staking/admin/toggle_mock_time").SignProposeAndPayAs("account").
Test(t).
AssertSuccess()
}
type FarmMeta struct {
FarmWeightsByID struct {
uint64 float64
}
Id json.Number
LastRewardTimestamp json.Number
RewardTokensPerSecondByID map[string]json.Number
Stakes map[string]Stake
TotalAccumulatedTokensPerShareByID map[string]json.Number
TotalStaked json.Number
RewardsRemainingByID map[string]json.Number
}
type Stake struct {
Address string
Balance json.Number
PendingRewards map[string]json.Number
RewardDebtByID map[string]json.Number
}