github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/execution/testutil/fixtures_token.go (about) 1 package testutil 2 3 import ( 4 "fmt" 5 6 "github.com/onflow/cadence" 7 jsoncdc "github.com/onflow/cadence/encoding/json" 8 9 "github.com/onflow/flow-go/fvm/systemcontracts" 10 "github.com/onflow/flow-go/model/flow" 11 ) 12 13 func CreateTokenTransferTransaction(chain flow.Chain, amount int, to flow.Address, signer flow.Address) *flow.TransactionBody { 14 sc := systemcontracts.SystemContractsForChain(chain.ChainID()) 15 return flow.NewTransactionBody(). 16 SetScript([]byte(fmt.Sprintf(` 17 import FungibleToken from 0x%s 18 import FlowToken from 0x%s 19 20 transaction(amount: UFix64, to: Address) { 21 let sentVault: @{FungibleToken.Vault} 22 23 prepare(signer: auth(BorrowValue) &Account) { 24 let vaultRef = signer.storage.borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(from: /storage/flowTokenVault) 25 ?? panic("Could not borrow reference to the owner's Vault!") 26 self.sentVault <- vaultRef.withdraw(amount: amount) 27 } 28 29 execute { 30 let receiverRef = getAccount(to) 31 .capabilities.borrow<&{FungibleToken.Receiver}>(/public/flowTokenReceiver) 32 ?? panic("Could not borrow receiver reference to the recipient's Vault") 33 receiverRef.deposit(from: <-self.sentVault) 34 } 35 }`, sc.FungibleToken.Address.Hex(), sc.FlowToken.Address.Hex()))). 36 AddArgument(jsoncdc.MustEncode(cadence.UFix64(amount))). 37 AddArgument(jsoncdc.MustEncode(cadence.NewAddress(to))). 38 AddAuthorizer(signer) 39 }