-
Notifications
You must be signed in to change notification settings - Fork 175
/
fixtures_token.go
39 lines (32 loc) · 1.24 KB
/
fixtures_token.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
package testutil
import (
"fmt"
"github.com/onflow/cadence"
jsoncdc "github.com/onflow/cadence/encoding/json"
"github.com/onflow/flow-go/fvm"
"github.com/onflow/flow-go/model/flow"
)
func CreateTokenTransferTransaction(chain flow.Chain, amount int, to flow.Address, signer flow.Address) *flow.TransactionBody {
return flow.NewTransactionBody().
SetScript([]byte(fmt.Sprintf(`
import FungibleToken from 0x%s
import FlowToken from 0x%s
transaction(amount: UFix64, to: Address) {
let sentVault: @FungibleToken.Vault
prepare(signer: AuthAccount) {
let vaultRef = signer.borrow<&FlowToken.Vault>(from: /storage/flowTokenVault)
?? panic("Could not borrow reference to the owner's Vault!")
self.sentVault <- vaultRef.withdraw(amount: amount)
}
execute {
let receiverRef = getAccount(to)
.getCapability(/public/flowTokenReceiver)
.borrow<&{FungibleToken.Receiver}>()
?? panic("Could not borrow receiver reference to the recipient's Vault")
receiverRef.deposit(from: <-self.sentVault)
}
}`, fvm.FungibleTokenAddress(chain), fvm.FlowTokenAddress(chain)))).
AddArgument(jsoncdc.MustEncode(cadence.UFix64(amount))).
AddArgument(jsoncdc.MustEncode(cadence.NewAddress(to))).
AddAuthorizer(signer)
}