github.com/koko1123/flow-go-1@v0.29.6/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/koko1123/flow-go-1/fvm"
    10  	"github.com/koko1123/flow-go-1/model/flow"
    11  )
    12  
    13  func CreateTokenTransferTransaction(chain flow.Chain, amount int, to flow.Address, signer flow.Address) *flow.TransactionBody {
    14  	return flow.NewTransactionBody().
    15  		SetScript([]byte(fmt.Sprintf(`
    16  		import FungibleToken from 0x%s
    17  		import FlowToken from 0x%s
    18  
    19  		transaction(amount: UFix64, to: Address) {
    20  			let sentVault: @FungibleToken.Vault
    21  
    22  			prepare(signer: AuthAccount) {
    23  				let vaultRef = signer.borrow<&FlowToken.Vault>(from: /storage/flowTokenVault)
    24  					?? panic("Could not borrow reference to the owner's Vault!")
    25  				self.sentVault <- vaultRef.withdraw(amount: amount)
    26  			}
    27  
    28  			execute {
    29  				let receiverRef = getAccount(to)
    30  					.getCapability(/public/flowTokenReceiver)
    31  					.borrow<&{FungibleToken.Receiver}>()
    32  					?? panic("Could not borrow receiver reference to the recipient's Vault")
    33  				receiverRef.deposit(from: <-self.sentVault)
    34  			}
    35  		}`, fvm.FungibleTokenAddress(chain), fvm.FlowTokenAddress(chain)))).
    36  		AddArgument(jsoncdc.MustEncode(cadence.UFix64(amount))).
    37  		AddArgument(jsoncdc.MustEncode(cadence.NewAddress(to))).
    38  		AddAuthorizer(signer)
    39  }