-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEMUTestUtils.go
More file actions
61 lines (52 loc) · 1.81 KB
/
Copy pathEMUTestUtils.go
File metadata and controls
61 lines (52 loc) · 1.81 KB
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
package main
import (
"fmt"
"strconv"
"testing"
"github.com/bjartek/overflow/overflow"
"github.com/stretchr/testify/assert"
)
type OverflowTestUtils struct {
T *testing.T
O *overflow.Overflow
}
func (otu *OverflowTestUtils) setupFUSDVaultWithBalance(o *overflow.Overflow, account string, amount float64) *OverflowTestUtils {
otu.O.TransactionFromFile("FUSD/setup").SignProposeAndPayAs(account).RunPrintEventsFull()
otu.O.TransactionFromFile("demo/mintFUSD").SignProposeAndPayAs("account").Args(o.Arguments().UFix64(amount).Address(account)).RunPrintEventsFull()
return otu
}
func (otu *OverflowTestUtils) createPoolFlowFUSD(o *overflow.Overflow, account string, flowAmount float64, fusdAmount float64) *OverflowTestUtils {
otu.O.TransactionFromFile("EmuSwap/admin/create_new_pool_FLOW_FUSD").
SignProposeAndPayAs("account").
Args(o.
Arguments().
UFix64(flowAmount).
UFix64(fusdAmount)).
Test(otu.T).AssertSuccess()
return otu
}
func (otu *OverflowTestUtils) getPoolMeta() *OverflowTestUtils {
otu.O.ScriptFromFile("get_pool_meta")
return otu
}
func (otu *OverflowTestUtils) tickClock(time float64) *OverflowTestUtils {
otu.O.TransactionFromFile("clock").SignProposeAndPayAs("find").
Args(otu.O.Arguments().
UFix64(time)).
Test(otu.T).AssertSuccess()
return otu
}
func (out *OverflowTestUtils) currentTime() float64 {
value, err := out.O.Script(`import Clock from "../contracts/Clock.cdc"
pub fun main() : UFix64 {
return Clock.time()
}`).RunReturns()
assert.NoErrorf(out.T, err, "Could not execute script")
currentTime := value.String()
res, err := strconv.ParseFloat(currentTime, 64)
assert.NoErrorf(out.T, err, "Could not parse as float")
return res
}
func (otu *OverflowTestUtils) accountAddress(name string) string {
return fmt.Sprintf("0x%s", otu.O.Account(name).Address().String())
}