github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/execution/testutil/fixtures_event.go (about)

     1  package testutil
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/onflow/flow-go/model/flow"
     7  )
     8  
     9  const EventContract = `
    10  access(all) contract EventContract {
    11  
    12  	access(all) event TestEvent(value: Int16)
    13  
    14  	access(all) fun EmitEvent() {
    15  		emit TestEvent(value: %d)
    16  	}
    17  }
    18  `
    19  
    20  func DeployEventContractTransaction(authorizer flow.Address, chain flow.Chain, eventValue int) *flow.TransactionBody {
    21  	contract := fmt.Sprintf(EventContract, eventValue)
    22  	return CreateContractDeploymentTransaction("EventContract", contract, authorizer, chain)
    23  }
    24  
    25  func UnauthorizedDeployEventContractTransaction(authorizer flow.Address, chain flow.Chain, eventValue int) *flow.TransactionBody {
    26  	contract := fmt.Sprintf(EventContract, eventValue)
    27  	return CreateUnauthorizedContractDeploymentTransaction("EventContract", contract, authorizer)
    28  }
    29  
    30  func UpdateEventContractTransaction(authorizer flow.Address, chain flow.Chain, eventValue int) *flow.TransactionBody {
    31  	contract := fmt.Sprintf(EventContract, eventValue)
    32  	return UpdateContractDeploymentTransaction("EventContract", contract, authorizer, chain)
    33  }
    34  
    35  func CreateEmitEventTransaction(contractAccount, signer flow.Address) *flow.TransactionBody {
    36  	return flow.NewTransactionBody().
    37  		SetScript([]byte(fmt.Sprintf(`
    38  			import EventContract from 0x%s
    39  
    40  			transaction {
    41  				prepare(acc: &Account) {}
    42  				execute {
    43  					EventContract.EmitEvent()
    44  				}
    45  			}`, contractAccount)),
    46  		).
    47  		AddAuthorizer(signer)
    48  }