diff --git a/templates/accounts.go b/templates/accounts.go index 7cb71a78b..3bef10afb 100644 --- a/templates/accounts.go +++ b/templates/accounts.go @@ -45,11 +45,13 @@ type Contract struct { Source string } +// Deprecated // SourceBytes returns the UTF-8 encoded source code (Source) of the contract. func (c Contract) SourceBytes() []byte { return []byte(c.Source) } +// Deprecated // SourceHex returns the UTF-8 encoded source code (Source) of the contract as a hex string. func (c Contract) SourceHex() string { return hex.EncodeToString(c.SourceBytes()) @@ -207,7 +209,7 @@ func CreateAccountAndFund( for i, contract := range contracts { contractKeyPairs[i] = cadence.KeyValuePair{ Key: cadence.String(contract.Name), - Value: cadence.String(contract.SourceHex()), + Value: cadence.String(contract.Source), } } @@ -264,7 +266,7 @@ func CreateAccountAndFund( // UpdateAccountContract generates a transaction that updates a contract deployed at an account. func UpdateAccountContract(address flow.Address, contract Contract) *flow.Transaction { cadenceName := cadence.String(contract.Name) - cadenceCode := cadence.String(contract.SourceHex()) + cadenceCode := cadence.String(contract.Source) return flow.NewTransaction(). SetScript([]byte(templates.UpdateContract)). @@ -276,7 +278,7 @@ func UpdateAccountContract(address flow.Address, contract Contract) *flow.Transa // AddAccountContract generates a transaction that deploys a contract to an account. func AddAccountContract(address flow.Address, contract Contract) *flow.Transaction { cadenceName := cadence.String(contract.Name) - cadenceCode := cadence.String(contract.SourceHex()) + cadenceCode := cadence.String(contract.Source) return flow.NewTransaction(). SetScript([]byte(templates.AddContract)). diff --git a/templates/accounts_test.go b/templates/accounts_test.go index 5b4d8b616..e775bb6ea 100644 --- a/templates/accounts_test.go +++ b/templates/accounts_test.go @@ -31,14 +31,12 @@ func TestCreateAccount(t *testing.T) { // Converting transaction arguments to Cadence values can increase their size. // If this is not taken into account the transaction can quickly grow over the maximum transaction size limit. t.Run("Transaction should not grow uncontrollably in size", func(t *testing.T) { - contractLen := 1000 - contractCode := make([]byte, contractLen) - + testContractBody := "test contract" tx, err := templates.CreateAccount( []*flow.AccountKey{}, []templates.Contract{{ Name: "contract", - Source: string(contractCode), + Source: testContractBody, }}, flow.HexToAddress("01")) @@ -50,8 +48,7 @@ func TestCreateAccount(t *testing.T) { argumentsSize += len(argument) } require.Less(t, txSize, 1000, "The create account script should not grow over 1kB.") - require.Less(t, argumentsSize, contractLen*2+500, - "The create account argument size should not grow over "+ - "2 times the contract code (converted to hex) + 500 bytes of extra data.") + require.Less(t, argumentsSize, len(testContractBody)+500, + "The create account argument size should not grow over 500 bytes of extra data.") }) }