-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
130 lines (111 loc) · 3.13 KB
/
main_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
package test
import (
"testing"
"github.com/bjartek/overflow"
)
// Owner creates a farm, plants seeds, employs a worker and harvests the crop
func TestFarmOwner(t *testing.T) {
// Start emulator and deploy contracts
o := overflow.Overflow()
// Step 1: Create a farm and plant seeds
o.Tx(
"owner/1_plant",
overflow.WithSigner("owner"),
).AssertSuccess(t).
AssertEvent(t, "StrawberrySeed.TokensMinted", map[string]interface{}{
"amount": 10.0,
}).
AssertEvent(t, "FlowFarm.SeedsPlanted", map[string]interface{}{
"amount": 10.0,
})
// Advance 10 blocks
noop(o, 10)
// Step 2: Employ a worker to start harvesting
o.Tx(
"owner/2_employ",
overflow.WithSigner("owner"),
).AssertSuccess(t).
AssertEmitEventName(t, "FlowFarm.FarmerEmployed")
// Advance 10 blocks
noop(o, 10)
// Step 3: Harvest the strawberries
o.Tx(
"owner/3_harvest",
overflow.WithSigner("owner"),
).AssertSuccess(t).
AssertEmitEventName(t, "FlowFarm.FarmerRetired").
AssertEvent(t, "FlowFarm.StrawberryHarvested", map[string]interface{}{
"amount": 10.0,
}).
AssertEvent(t, "FlowFarm.FarmerEnergyUsed", map[string]interface{}{
"amount": 10.0,
}).
AssertEvent(t, "Strawberry.TokensMinted", map[string]interface{}{
"amount": 10.0,
}).
AssertEvent(t, "Strawberry.TokensDeposited", map[string]interface{}{
"amount": 10.0,
"to": "0x179b6b1cb6755e31",
})
}
func TestPickingContract(t *testing.T) {
// Start emulator and deploy contracts
o := overflow.Overflow(overflow.WithFlowForNewUsers(100))
// Step 1: Create a farm and plant seeds. Create a new contract so another
// player can deposit their Farmer
o.Tx(
"contractor/1_issue",
overflow.WithSigner("owner"),
).AssertSuccess(t).
AssertEvent(t, "StrawberrySeed.TokensMinted", map[string]interface{}{
"amount": 10.0,
}).
AssertEvent(t, "FlowFarm.SeedsPlanted", map[string]interface{}{
"amount": 10.0,
})
// Advance 10 blocks
noop(o, 10)
// Step 2: Another user creates a Farmer and employs them for harvesting.
o.Tx(
"contractor/2_employ",
overflow.WithArg("contractAddress", "owner"),
overflow.WithSigner("contractor"),
).AssertSuccess(t).
AssertEmitEventName(t, "FlowFarm.FarmerEmployed").
AssertEvent(t, "FlowToken.TokensDeposited", map[string]interface{}{
"amount": 10.0,
})
// Advance 10 blocks
noop(o, 10)
// Step 3: Withdraw Farmer
o.Tx(
"contractor/3_withdraw",
overflow.WithArg("contractAddress", "owner"),
overflow.WithSigner("contractor"),
).AssertSuccess(t).
AssertEmitEventName(t, "FlowFarm.FarmerRetired").
AssertEvent(t, "FlowFarm.StrawberryHarvested", map[string]interface{}{
"amount": 10.0,
}).
AssertEvent(t, "FlowFarm.FarmerEnergyUsed", map[string]interface{}{
"amount": 10.0,
}).
AssertEvent(t, "Strawberry.TokensMinted", map[string]interface{}{
"amount": 10.0,
}).
AssertEvent(t, "Strawberry.TokensDeposited", map[string]interface{}{
"amount": 10.0,
"to": "0x179b6b1cb6755e31",
})
}
// noop runs a noop transaction to advance block height in emulator
func noop(o *overflow.OverflowState, num int) {
i := 0
for i < num {
o.Tx(
"noop",
overflow.WithSigner("owner"),
)
i += 1
}
}