-
Notifications
You must be signed in to change notification settings - Fork 20
/
doc_test.go
129 lines (115 loc) Β· 4.19 KB
/
doc_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
package overflow_test
// importing overflow using "." will yield a cleaner DSL
import (
. "github.com/bjartek/overflow/v2"
)
var docOptions = WithGlobalPrintOptions(WithoutId())
func Example() {
// in order to start overflow use the Overflow function
// it can be customized with lots of OverflowOption
Overflow()
//Output:
//π§ Created account: emulator-first with address: 179b6b1cb6755e31 with flow: 10.00
//π§ Created account: emulator-second with address: f3fcd2c1a78f5eee with flow: 10.00
//π deploy contracts Debug
}
func ExampleOverflowState_Tx() {
o := Overflow(docOptions)
// start the Tx DSL with the name of the transactions file, by default this
// is in the `transactions` folder in your root dit
o.Tx("arguments",
// Customize the Transaction by sending in more InteractionOptions,
// at minimum you need to set Signer and Args if any
WithSigner("first"),
// Arguments are always passed by name in the DSL builder, order does not matter
WithArg("test", "overflow ftw!"),
)
//Output:
//π§ Created account: emulator-first with address: 179b6b1cb6755e31 with flow: 10.00
//π§ Created account: emulator-second with address: f3fcd2c1a78f5eee with flow: 10.00
//π deploy contracts Debug
//π Tx:arguments fee:0.00001000 gas:4
//
}
func ExampleOverflowState_Tx_inline() {
o := Overflow(docOptions)
// The Tx dsl can also contain an inline transaction
o.Tx(`
import Debug from "../contracts/Debug.cdc"
transaction(message:String) {
prepare(acct: &Account) {
Debug.log(message)
}
}`,
WithSigner("first"),
WithArg("message", "overflow ftw!"),
)
//Output:
//π§ Created account: emulator-first with address: 179b6b1cb6755e31 with flow: 10.00
//π§ Created account: emulator-second with address: f3fcd2c1a78f5eee with flow: 10.00
//π deploy contracts Debug
//π Tx: fee:0.00001000 gas:7
//=== Events ===
//A.f8d6e0586b0a20c7.Debug.Log
// msg -> overflow ftw!
}
func ExampleOverflowState_Tx_multisign() {
o := Overflow(docOptions)
// The Tx dsl supports multiple signers, note that the mainSigner is the last account
o.Tx(`
import Debug from "../contracts/Debug.cdc"
transaction {
prepare(acct: &Account, acct2: &Account) {
Debug.log("acct:".concat(acct.address.toString()))
Debug.log("acct2:".concat(acct2.address.toString()))
}
}`,
WithSigner("first"),
WithPayloadSigner("second"),
)
//Output:
//π§ Created account: emulator-first with address: 179b6b1cb6755e31 with flow: 10.00
//π§ Created account: emulator-second with address: f3fcd2c1a78f5eee with flow: 10.00
//π deploy contracts Debug
//π Tx: fee:0.00001000 gas:7
//=== Events ===
//A.f8d6e0586b0a20c7.Debug.Log
// msg -> acct:0xf3fcd2c1a78f5eee
//A.f8d6e0586b0a20c7.Debug.Log
// msg -> acct2:0x179b6b1cb6755e31
}
func ExampleOverflowState_Script() {
o := Overflow(docOptions)
// the other major interaction you can run on Flow is a script, it uses the script DSL.
// Start it by specifying the script name from `scripts` folder
o.Script("test",
// the test script requires an address as arguments, Overflow is smart enough that it
// sees this and knows that there is an account for the emulator network called
// `emulator-first` so it will insert that address as the argument.
// If you change the network to testnet/mainnet later and name your stakholders
// accordingly it will just work
WithArg("account", "first"),
)
//Output:
//
//π§ Created account: emulator-first with address: 179b6b1cb6755e31 with flow: 10.00
//π§ Created account: emulator-second with address: f3fcd2c1a78f5eee with flow: 10.00
//π deploy contracts Debug
//β Script test run result:"0x179b6b1cb6755e31"
}
func ExampleOverflowState_Script_inline() {
o := Overflow(docOptions)
// Script can be run inline
o.Script(`
access(all) fun main(account: Address): String {
return getAccount(account).address.toString()
}`,
WithArg("account", "first"),
WithName("get_address"),
)
//Output:
//π§ Created account: emulator-first with address: 179b6b1cb6755e31 with flow: 10.00
//π§ Created account: emulator-second with address: f3fcd2c1a78f5eee with flow: 10.00
//π deploy contracts Debug
//β Script get_address run result:"0x179b6b1cb6755e31"
}