From 002e16f8d121c494927344f48ac5637411c22f9a Mon Sep 17 00:00:00 2001 From: Illia Malachyn Date: Mon, 10 Jun 2024 19:17:54 +0300 Subject: [PATCH 1/7] Add a new script that checks if payer has balance to pay for tx --- lib/go/templates/internal/assets/assets.go | 23 +++++++++++++++++++ lib/go/templates/service_templates.go | 8 +++++++ lib/go/test/service_test.go | 15 ++++++++++++ .../check_if_payer_has_sufficient_balance.cdc | 8 +++++++ 4 files changed, 54 insertions(+) create mode 100644 transactions/FlowServiceAccount/scripts/check_if_payer_has_sufficient_balance.cdc diff --git a/lib/go/templates/internal/assets/assets.go b/lib/go/templates/internal/assets/assets.go index 4bb33f61d..119b0018b 100644 --- a/lib/go/templates/internal/assets/assets.go +++ b/lib/go/templates/internal/assets/assets.go @@ -3,6 +3,7 @@ // FlowServiceAccount/add_account_creator.cdc (565B) // FlowServiceAccount/deposit_fees.cdc (838B) // FlowServiceAccount/remove_account_creator.cdc (567B) +// FlowServiceAccount/scripts/check_if_payer_has_sufficient_balance.cdc (365B) // FlowServiceAccount/scripts/get_account_creators.cdc (133B) // FlowServiceAccount/scripts/get_account_fee.cdc (128B) // FlowServiceAccount/scripts/get_execution_effort_weights.cdc (147B) @@ -425,6 +426,26 @@ func flowserviceaccountRemove_account_creatorCdc() (*asset, error) { return a, nil } +var _flowserviceaccountScriptsCheck_if_payer_has_sufficient_balanceCdc = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x6c\x8f\xc1\x4a\xf4\x30\x14\x85\xf7\x7d\x8a\xb3\x9c\x42\x19\xfe\xc5\x8f\x8b\x82\x8b\x0e\x93\xac\x04\xc5\x2a\xae\x63\xe6\x46\x03\x69\x52\x6e\x6e\xb4\x83\xf8\xee\xd2\xea\x38\x62\xcd\x2e\x27\x87\xf3\x7d\xf1\xc3\x98\x58\xa0\x43\x7a\xd5\x44\x19\x8e\xd3\x80\x7f\x93\xbe\xba\x7e\xd0\x4a\xf5\xdd\x7e\x7f\xab\xfa\xbe\xaa\xc6\xf2\x08\x57\x22\x06\xe3\xe3\x66\x34\x47\xe2\xce\x5a\x69\xd1\x1d\x0e\x4c\x39\x37\xf0\xd1\x86\x92\x7d\x8a\xca\xb9\xc4\xd2\xe2\x5e\xfb\xe9\xe2\x7f\x83\xc1\x4c\x6a\x22\x5b\x64\xf5\x56\xb7\xd8\xa5\x14\xf0\x56\x01\x40\x20\x81\x29\xf2\x3c\xef\xe2\x12\x4f\x24\xdd\xe7\x2d\x95\x28\x67\x64\xbd\x94\x99\xa4\x70\xfc\xd6\xde\xbe\x10\x7b\x77\xbc\x99\x4b\x79\x67\x82\x89\x96\x74\xe2\x3b\x36\x31\x1b\xbb\x90\x4f\x0a\x9b\x13\xa3\x59\x86\xe6\xb3\x52\xff\x15\x9c\x9b\x7f\xfd\x65\x9d\xd5\x5b\x6b\xbe\x80\xf4\x43\xa1\x7a\xff\x08\x00\x00\xff\xff\x9c\x72\xaf\x4b\x6d\x01\x00\x00" + +func flowserviceaccountScriptsCheck_if_payer_has_sufficient_balanceCdcBytes() ([]byte, error) { + return bindataRead( + _flowserviceaccountScriptsCheck_if_payer_has_sufficient_balanceCdc, + "FlowServiceAccount/scripts/check_if_payer_has_sufficient_balance.cdc", + ) +} + +func flowserviceaccountScriptsCheck_if_payer_has_sufficient_balanceCdc() (*asset, error) { + bytes, err := flowserviceaccountScriptsCheck_if_payer_has_sufficient_balanceCdcBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "FlowServiceAccount/scripts/check_if_payer_has_sufficient_balance.cdc", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x35, 0x10, 0x91, 0xc5, 0x3, 0x62, 0x38, 0x50, 0x45, 0x25, 0x76, 0xc7, 0xf6, 0xc0, 0x41, 0xd9, 0xc2, 0x6f, 0xca, 0xa0, 0x43, 0xcd, 0x4, 0x1a, 0x14, 0xb5, 0x73, 0x28, 0x8f, 0x2e, 0x97, 0x7f}} + return a, nil +} + var _flowserviceaccountScriptsGet_account_creatorsCdc = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xca\xcc\x2d\xc8\x2f\x2a\x51\x70\xcb\xc9\x2f\x0f\x4e\x2d\x2a\xcb\x4c\x4e\x75\x4c\x4e\xce\x2f\xcd\x2b\x51\x48\x2b\xca\xcf\x55\x30\xa8\x70\xf3\xf1\x0f\x0f\x76\x0d\x0a\xf3\x74\x76\x75\x74\x71\x09\x72\x0d\x0e\xe6\xe2\x2a\x28\x4d\x52\x48\x2b\xcd\x53\xc8\x4d\xcc\xcc\xd3\xd0\xb4\x52\x88\x76\x4c\x49\x29\x4a\x2d\x2e\x8e\x55\xa8\xe6\x52\x50\x50\x50\x28\x4a\x2d\x29\x2d\xca\xc3\x62\xa8\x5e\x7a\x6a\x09\x94\xe9\x5c\x94\x9a\x58\x92\x5f\x54\xac\xa1\xc9\x55\x0b\x08\x00\x00\xff\xff\x3a\x18\x2d\x67\x85\x00\x00\x00" func flowserviceaccountScriptsGet_account_creatorsCdcBytes() ([]byte, error) { @@ -6379,6 +6400,7 @@ var _bindata = map[string]func() (*asset, error){ "FlowServiceAccount/add_account_creator.cdc": flowserviceaccountAdd_account_creatorCdc, "FlowServiceAccount/deposit_fees.cdc": flowserviceaccountDeposit_feesCdc, "FlowServiceAccount/remove_account_creator.cdc": flowserviceaccountRemove_account_creatorCdc, + "FlowServiceAccount/scripts/check_if_payer_has_sufficient_balance.cdc": flowserviceaccountScriptsCheck_if_payer_has_sufficient_balanceCdc, "FlowServiceAccount/scripts/get_account_creators.cdc": flowserviceaccountScriptsGet_account_creatorsCdc, "FlowServiceAccount/scripts/get_account_fee.cdc": flowserviceaccountScriptsGet_account_feeCdc, "FlowServiceAccount/scripts/get_execution_effort_weights.cdc": flowserviceaccountScriptsGet_execution_effort_weightsCdc, @@ -6723,6 +6745,7 @@ var _bintree = &bintree{nil, map[string]*bintree{ "deposit_fees.cdc": {flowserviceaccountDeposit_feesCdc, map[string]*bintree{}}, "remove_account_creator.cdc": {flowserviceaccountRemove_account_creatorCdc, map[string]*bintree{}}, "scripts": {nil, map[string]*bintree{ + "check_if_payer_has_sufficient_balance.cdc": {flowserviceaccountScriptsCheck_if_payer_has_sufficient_balanceCdc, map[string]*bintree{}}, "get_account_creators.cdc": {flowserviceaccountScriptsGet_account_creatorsCdc, map[string]*bintree{}}, "get_account_fee.cdc": {flowserviceaccountScriptsGet_account_feeCdc, map[string]*bintree{}}, "get_execution_effort_weights.cdc": {flowserviceaccountScriptsGet_execution_effort_weightsCdc, map[string]*bintree{}}, diff --git a/lib/go/templates/service_templates.go b/lib/go/templates/service_templates.go index 65da666ff..1707cc439 100644 --- a/lib/go/templates/service_templates.go +++ b/lib/go/templates/service_templates.go @@ -38,6 +38,8 @@ const ( setExecutionMemoryWeighs = "FlowServiceAccount/set_execution_memory_weights.cdc" getExecutionMemoryLimit = "FlowServiceAccount/scripts/get_execution_memory_limit.cdc" setExecutionMemoryLimit = "FlowServiceAccount/set_execution_memory_limit.cdc" + + checkIfPayerHasSufficientBalance = "FlowServiceAccount/scripts/check_if_payer_has_sufficient_balance.cdc" ) // FlowToken Templates @@ -192,3 +194,9 @@ func GenerateGetExecutionMemoryLimit(env Environment) []byte { return []byte(ReplaceAddresses(code, env)) } + +func GenerateCheckIfPayerHasSufficientBalance(env Environment) []byte { + code := assets.MustAssetString(checkIfPayerHasSufficientBalance) + + return []byte(ReplaceAddresses(code, env)) +} diff --git a/lib/go/test/service_test.go b/lib/go/test/service_test.go index 626bb59b5..9b8acf50c 100644 --- a/lib/go/test/service_test.go +++ b/lib/go/test/service_test.go @@ -399,6 +399,21 @@ func TestContracts(t *testing.T) { }) + t.Run("Should check if payer has sufficient balance to execute tx", func(t *testing.T) { + // TODO: Is it better to set up a mock tx and test against it? + + // TODO: What account should I use here? + account := cadence.NewAddress(flow.HexToAddress(env.FlowFeesAddress)) + inclusionEffort := cadence.UFix64(1) + gasLimit := cadence.UFix64(99) + + args := [][]byte{jsoncdc.MustEncode(account), jsoncdc.MustEncode(inclusionEffort), jsoncdc.MustEncode(gasLimit)} + + result = executeScriptAndCheck(t, b, templates.GenerateCheckIfPayerHasSufficientBalance(env), args) + require.NotNil(t, result) + require.True(t, result.(cadence.Bool).ToGoValue().(bool)) + }) + // deploy the ServiceAccount contract serviceAccountCode := contracts.FlowServiceAccount( emulatorFTAddress, diff --git a/transactions/FlowServiceAccount/scripts/check_if_payer_has_sufficient_balance.cdc b/transactions/FlowServiceAccount/scripts/check_if_payer_has_sufficient_balance.cdc new file mode 100644 index 000000000..b0261ad24 --- /dev/null +++ b/transactions/FlowServiceAccount/scripts/check_if_payer_has_sufficient_balance.cdc @@ -0,0 +1,8 @@ +import FlowFees from 0xFLOWFEESADDRESS + +pub fun main(payerAcct: Address, inclusionEffort: UFix64, maxExecutionEffort: UFix64): Bool { + let authAcct = getAuthAccount(payerAcct) + return FlowFees.verifyPayersBalanceForTransactionExecution(authAcct, + inclusionEffort: inclusionEffort, + maxExecutionEffort: maxExecutionEffort).canExecuteTransaction +} \ No newline at end of file From 0707fa3a3718872ab8bdfb0266e6b64116d112a5 Mon Sep 17 00:00:00 2001 From: Illia Malachyn Date: Tue, 11 Jun 2024 13:01:43 +0300 Subject: [PATCH 2/7] Rewrite check_if_payer_has_sufficient_balance to return struct --- lib/go/templates/internal/assets/assets.go | 46 +++++++++---------- lib/go/templates/service_templates.go | 6 +-- lib/go/test/service_test.go | 15 +++--- ...verify_payer_balance_for_tx_execution.cdc} | 7 ++- 4 files changed, 37 insertions(+), 37 deletions(-) rename transactions/FlowServiceAccount/scripts/{check_if_payer_has_sufficient_balance.cdc => verify_payer_balance_for_tx_execution.cdc} (58%) diff --git a/lib/go/templates/internal/assets/assets.go b/lib/go/templates/internal/assets/assets.go index 119b0018b..26da1d51b 100644 --- a/lib/go/templates/internal/assets/assets.go +++ b/lib/go/templates/internal/assets/assets.go @@ -3,7 +3,6 @@ // FlowServiceAccount/add_account_creator.cdc (565B) // FlowServiceAccount/deposit_fees.cdc (838B) // FlowServiceAccount/remove_account_creator.cdc (567B) -// FlowServiceAccount/scripts/check_if_payer_has_sufficient_balance.cdc (365B) // FlowServiceAccount/scripts/get_account_creators.cdc (133B) // FlowServiceAccount/scripts/get_account_fee.cdc (128B) // FlowServiceAccount/scripts/get_execution_effort_weights.cdc (147B) @@ -13,6 +12,7 @@ // FlowServiceAccount/scripts/get_is_account_creation_restricted.cdc (137B) // FlowServiceAccount/scripts/get_is_account_creator.cdc (149B) // FlowServiceAccount/scripts/get_tx_fee_parameters.cdc (121B) +// FlowServiceAccount/scripts/verify_payer_balance_for_tx_execution.cdc (364B) // FlowServiceAccount/set_execution_effort_weights.cdc (1.636kB) // FlowServiceAccount/set_execution_memory_limit.cdc (260B) // FlowServiceAccount/set_execution_memory_weights.cdc (288B) @@ -426,26 +426,6 @@ func flowserviceaccountRemove_account_creatorCdc() (*asset, error) { return a, nil } -var _flowserviceaccountScriptsCheck_if_payer_has_sufficient_balanceCdc = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x6c\x8f\xc1\x4a\xf4\x30\x14\x85\xf7\x7d\x8a\xb3\x9c\x42\x19\xfe\xc5\x8f\x8b\x82\x8b\x0e\x93\xac\x04\xc5\x2a\xae\x63\xe6\x46\x03\x69\x52\x6e\x6e\xb4\x83\xf8\xee\xd2\xea\x38\x62\xcd\x2e\x27\x87\xf3\x7d\xf1\xc3\x98\x58\xa0\x43\x7a\xd5\x44\x19\x8e\xd3\x80\x7f\x93\xbe\xba\x7e\xd0\x4a\xf5\xdd\x7e\x7f\xab\xfa\xbe\xaa\xc6\xf2\x08\x57\x22\x06\xe3\xe3\x66\x34\x47\xe2\xce\x5a\x69\xd1\x1d\x0e\x4c\x39\x37\xf0\xd1\x86\x92\x7d\x8a\xca\xb9\xc4\xd2\xe2\x5e\xfb\xe9\xe2\x7f\x83\xc1\x4c\x6a\x22\x5b\x64\xf5\x56\xb7\xd8\xa5\x14\xf0\x56\x01\x40\x20\x81\x29\xf2\x3c\xef\xe2\x12\x4f\x24\xdd\xe7\x2d\x95\x28\x67\x64\xbd\x94\x99\xa4\x70\xfc\xd6\xde\xbe\x10\x7b\x77\xbc\x99\x4b\x79\x67\x82\x89\x96\x74\xe2\x3b\x36\x31\x1b\xbb\x90\x4f\x0a\x9b\x13\xa3\x59\x86\xe6\xb3\x52\xff\x15\x9c\x9b\x7f\xfd\x65\x9d\xd5\x5b\x6b\xbe\x80\xf4\x43\xa1\x7a\xff\x08\x00\x00\xff\xff\x9c\x72\xaf\x4b\x6d\x01\x00\x00" - -func flowserviceaccountScriptsCheck_if_payer_has_sufficient_balanceCdcBytes() ([]byte, error) { - return bindataRead( - _flowserviceaccountScriptsCheck_if_payer_has_sufficient_balanceCdc, - "FlowServiceAccount/scripts/check_if_payer_has_sufficient_balance.cdc", - ) -} - -func flowserviceaccountScriptsCheck_if_payer_has_sufficient_balanceCdc() (*asset, error) { - bytes, err := flowserviceaccountScriptsCheck_if_payer_has_sufficient_balanceCdcBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "FlowServiceAccount/scripts/check_if_payer_has_sufficient_balance.cdc", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x35, 0x10, 0x91, 0xc5, 0x3, 0x62, 0x38, 0x50, 0x45, 0x25, 0x76, 0xc7, 0xf6, 0xc0, 0x41, 0xd9, 0xc2, 0x6f, 0xca, 0xa0, 0x43, 0xcd, 0x4, 0x1a, 0x14, 0xb5, 0x73, 0x28, 0x8f, 0x2e, 0x97, 0x7f}} - return a, nil -} - var _flowserviceaccountScriptsGet_account_creatorsCdc = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xca\xcc\x2d\xc8\x2f\x2a\x51\x70\xcb\xc9\x2f\x0f\x4e\x2d\x2a\xcb\x4c\x4e\x75\x4c\x4e\xce\x2f\xcd\x2b\x51\x48\x2b\xca\xcf\x55\x30\xa8\x70\xf3\xf1\x0f\x0f\x76\x0d\x0a\xf3\x74\x76\x75\x74\x71\x09\x72\x0d\x0e\xe6\xe2\x2a\x28\x4d\x52\x48\x2b\xcd\x53\xc8\x4d\xcc\xcc\xd3\xd0\xb4\x52\x88\x76\x4c\x49\x29\x4a\x2d\x2e\x8e\x55\xa8\xe6\x52\x50\x50\x50\x28\x4a\x2d\x29\x2d\xca\xc3\x62\xa8\x5e\x7a\x6a\x09\x94\xe9\x5c\x94\x9a\x58\x92\x5f\x54\xac\xa1\xc9\x55\x0b\x08\x00\x00\xff\xff\x3a\x18\x2d\x67\x85\x00\x00\x00" func flowserviceaccountScriptsGet_account_creatorsCdcBytes() ([]byte, error) { @@ -626,6 +606,26 @@ func flowserviceaccountScriptsGet_tx_fee_parametersCdc() (*asset, error) { return a, nil } +var _flowserviceaccountScriptsVerify_payer_balance_for_tx_executionCdc = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x6c\x8f\x4d\x4b\xf4\x30\x14\x85\xf7\xfd\x15\x67\x39\x85\xf2\xf2\x2e\xc4\x45\xc1\x45\x65\x92\x95\xa0\x4c\xfd\x58\xc7\xcc\x8d\x06\xd2\xa4\xdc\xdc\x68\x07\xf1\xbf\x4b\xab\x63\xc1\x99\xec\x72\x12\x9e\xe7\x1c\x3f\x8c\x89\x05\x3a\xa4\x77\x4d\x94\xe1\x38\x0d\xf8\x3f\xe9\x9b\xdb\x27\xad\x54\xdf\x6d\xb7\x3b\xd5\xf7\x55\x35\x96\x67\xb8\x12\x31\x18\x1f\x37\xa3\x39\x10\x77\xd6\x4a\x8b\x6e\xbf\x67\xca\xb9\x81\x8f\x36\x94\xec\x53\x54\xce\x25\x96\x16\x0f\xda\x4f\x97\x17\x0d\x06\x33\xa9\x89\x6c\x91\x93\xb7\xba\xfd\xf5\xfe\x7b\x24\xf6\xee\x70\x37\x83\xaf\x4d\x30\xd1\xd2\x8e\x72\x09\x82\x8f\x0a\x00\x02\x09\x4c\x91\xd7\x59\x8a\x2b\xbc\x90\x74\xdf\xb7\x54\xa2\xac\x7d\xea\xe5\x33\x93\x14\x8e\x2b\xfb\x6d\x65\xe7\x1f\xb8\x4e\x7c\xcf\x26\x66\x63\x97\x5a\xc7\x7e\x9b\xa3\xe3\xcc\x9e\x3f\x41\xb3\xa8\xe6\x73\x6e\xe0\x69\x56\x57\x9f\x5f\x01\x00\x00\xff\xff\x84\x34\xe6\x41\x6c\x01\x00\x00" + +func flowserviceaccountScriptsVerify_payer_balance_for_tx_executionCdcBytes() ([]byte, error) { + return bindataRead( + _flowserviceaccountScriptsVerify_payer_balance_for_tx_executionCdc, + "FlowServiceAccount/scripts/verify_payer_balance_for_tx_execution.cdc", + ) +} + +func flowserviceaccountScriptsVerify_payer_balance_for_tx_executionCdc() (*asset, error) { + bytes, err := flowserviceaccountScriptsVerify_payer_balance_for_tx_executionCdcBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "FlowServiceAccount/scripts/verify_payer_balance_for_tx_execution.cdc", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xd7, 0x8, 0x1f, 0x86, 0x15, 0x31, 0x41, 0xb4, 0x3, 0xf0, 0x3, 0x18, 0x37, 0xf1, 0xe6, 0xe3, 0xc5, 0xc4, 0xac, 0xcb, 0x53, 0xc0, 0x41, 0x2d, 0xb1, 0x45, 0xc8, 0x22, 0xe, 0x5c, 0xe4, 0x25}} + return a, nil +} + var _flowserviceaccountSet_execution_effort_weightsCdc = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x93\x5d\x6b\xe3\x3a\x10\x86\xef\xf3\x2b\x06\x9f\x9b\x14\xd2\x38\x4e\x62\x27\x36\x87\x03\xa5\xe7\x14\xca\xe9\xc2\xc2\x7e\x5d\x94\x2e\x1d\xcb\xe3\x58\x5b\x4b\xf2\x4a\x72\xd2\x10\xf2\xdf\x17\x59\x71\x9b\x7e\xb0\xec\x2e\x7b\xb1\x86\x48\x62\xde\x99\x47\x6f\x34\x52\x18\xc2\xfb\x8a\x1b\xb0\x1a\xa5\x41\x66\xb9\x92\x06\x0c\x59\x03\x92\x36\x40\xf7\xc4\x5a\x17\x03\x2a\x4b\xa5\x2d\x6c\x88\xaf\x2a\x6b\x06\x5d\x19\x81\xc0\x7b\x2e\x5a\xf1\x32\xaf\xe6\x82\x5b\x28\x95\x7e\x0a\xe6\x06\xb0\xde\xe0\xd6\x40\xea\xbe\x71\xcf\xf1\x58\x90\x28\xc8\x84\xbc\x30\xc0\x50\x42\x4e\x60\x88\x24\x54\xa4\x29\x73\x99\xee\x77\x0a\xd7\xe7\x58\x90\x64\x04\xe7\x4a\x34\xad\x45\x47\xfe\x9f\xcb\xe2\x66\x58\x59\xdb\x98\x2c\x0c\x57\xdc\x56\x6d\x3e\x66\x4a\x84\x4a\x96\xb5\xda\x84\xcc\x97\x84\x79\xad\xf2\x30\x99\x2c\x62\x2a\xe7\x4b\xb6\x60\x53\x9c\x24\x51\x31\x5d\xd0\x2c\xc9\x27\x69\x8c\xb4\x20\x16\xd3\x74\x32\x8f\x19\x2e\x42\xdd\x4a\xcb\x05\x85\x4c\x09\xa1\xa4\x9b\xfa\xfd\xee\xb8\x2c\xc6\x2b\xf5\xd7\xd5\x6c\x72\x72\x70\x75\xf1\xf1\xcd\xcf\x38\x72\xc3\xe9\x4a\x79\x47\x51\x51\xce\x67\x05\x2d\x63\x16\xe7\x8b\x38\x89\x96\x71\x14\xe1\xb2\xa4\x34\xa5\x34\x4d\x97\x98\x4f\x69\xce\x8a\x38\x0d\xcb\xb5\x08\x05\x59\xd2\x7e\xec\x2c\xa4\xce\x81\x37\x61\x2b\x02\x2e\x2d\x69\x89\x35\x34\x9a\x18\x37\xae\x27\xaa\xec\x94\x17\x4d\xea\x18\xae\x27\xd3\xcf\x51\x32\x82\x4d\xc5\x59\x05\x82\x50\xfa\x88\x53\xe8\x6b\x8b\x35\x58\x05\x11\xa8\xd6\xf6\x24\xab\x2c\xd6\xbe\x85\x2f\xa9\xb8\x46\x5e\x63\x5e\xbb\x34\xc0\xe3\xfe\x8f\x0f\x46\x5d\xc7\x0b\x2a\xb1\xad\x1f\x2e\x14\xa0\xef\xb1\xff\x1f\xcf\xce\xf1\x4a\xa9\x26\x83\xe8\x55\xed\x9d\x45\x4b\x82\xa4\xcd\x20\x82\x57\x33\x2e\x5a\xd9\xed\x7e\x29\xd7\x8a\x75\x51\xcf\x72\xc9\x4a\x03\x97\xd0\xa0\x46\x7f\x16\xa5\xd2\xa2\xb7\x71\x7b\x7b\xfb\xc5\x28\xe9\x96\xd7\x6e\x00\xd8\xf9\x09\x20\xb0\xdb\x86\x82\x0c\x82\x7f\x79\x87\x46\xbd\x0d\x46\x0f\xe2\x1a\xeb\xd6\xa9\xd7\x7d\xe4\xa8\xb2\x4b\xb8\xa3\x6d\x90\xc1\xee\x11\xf3\xe1\x52\xda\x64\x1e\x8c\x1e\x6b\x83\x68\x32\x89\x02\xd8\x8f\x9e\x14\xf6\xea\xf7\x4b\x93\x38\x9e\x25\x01\xec\x1f\x4b\x8f\x31\xbf\x64\x65\xfa\xe7\x58\x99\xfd\x3e\x2b\xfd\xf2\xc6\x2f\x7a\xec\x11\xe7\x2d\xda\xea\x98\xb2\x83\xa0\x50\x02\xb9\x74\xa2\xb1\x4a\xe3\x8a\x9c\xce\x0b\x92\x96\x97\x9c\xb4\x13\x1e\x9e\xc4\x7f\xdd\x8b\xf8\xe4\xaf\x78\x00\x7b\xbf\xe5\xcd\xe1\x76\x0d\x8e\x9e\xc6\x50\xd2\xe6\x90\x97\xc1\xce\xdb\xcf\xc0\xcf\xfb\x13\xd8\x0d\x9c\xcf\x46\x53\x83\x9a\x86\x86\xaf\x24\xe9\x0c\xce\x5a\x5b\x9d\x31\xa6\x5a\x69\xfb\x14\xf7\x79\x79\x5c\x2b\x2c\xfe\x7e\x8e\xfa\x67\x58\x6a\x25\x32\x08\x0f\xe6\xc3\xd7\xbd\x9e\x3c\x87\x19\x5c\xd3\x91\xc7\x11\x58\xf5\x83\x90\xfd\x60\xff\x2d\x00\x00\xff\xff\xad\xdd\x1d\x36\x64\x06\x00\x00" func flowserviceaccountSet_execution_effort_weightsCdcBytes() ([]byte, error) { @@ -6400,7 +6400,6 @@ var _bindata = map[string]func() (*asset, error){ "FlowServiceAccount/add_account_creator.cdc": flowserviceaccountAdd_account_creatorCdc, "FlowServiceAccount/deposit_fees.cdc": flowserviceaccountDeposit_feesCdc, "FlowServiceAccount/remove_account_creator.cdc": flowserviceaccountRemove_account_creatorCdc, - "FlowServiceAccount/scripts/check_if_payer_has_sufficient_balance.cdc": flowserviceaccountScriptsCheck_if_payer_has_sufficient_balanceCdc, "FlowServiceAccount/scripts/get_account_creators.cdc": flowserviceaccountScriptsGet_account_creatorsCdc, "FlowServiceAccount/scripts/get_account_fee.cdc": flowserviceaccountScriptsGet_account_feeCdc, "FlowServiceAccount/scripts/get_execution_effort_weights.cdc": flowserviceaccountScriptsGet_execution_effort_weightsCdc, @@ -6410,6 +6409,7 @@ var _bindata = map[string]func() (*asset, error){ "FlowServiceAccount/scripts/get_is_account_creation_restricted.cdc": flowserviceaccountScriptsGet_is_account_creation_restrictedCdc, "FlowServiceAccount/scripts/get_is_account_creator.cdc": flowserviceaccountScriptsGet_is_account_creatorCdc, "FlowServiceAccount/scripts/get_tx_fee_parameters.cdc": flowserviceaccountScriptsGet_tx_fee_parametersCdc, + "FlowServiceAccount/scripts/verify_payer_balance_for_tx_execution.cdc": flowserviceaccountScriptsVerify_payer_balance_for_tx_executionCdc, "FlowServiceAccount/set_execution_effort_weights.cdc": flowserviceaccountSet_execution_effort_weightsCdc, "FlowServiceAccount/set_execution_memory_limit.cdc": flowserviceaccountSet_execution_memory_limitCdc, "FlowServiceAccount/set_execution_memory_weights.cdc": flowserviceaccountSet_execution_memory_weightsCdc, @@ -6745,7 +6745,6 @@ var _bintree = &bintree{nil, map[string]*bintree{ "deposit_fees.cdc": {flowserviceaccountDeposit_feesCdc, map[string]*bintree{}}, "remove_account_creator.cdc": {flowserviceaccountRemove_account_creatorCdc, map[string]*bintree{}}, "scripts": {nil, map[string]*bintree{ - "check_if_payer_has_sufficient_balance.cdc": {flowserviceaccountScriptsCheck_if_payer_has_sufficient_balanceCdc, map[string]*bintree{}}, "get_account_creators.cdc": {flowserviceaccountScriptsGet_account_creatorsCdc, map[string]*bintree{}}, "get_account_fee.cdc": {flowserviceaccountScriptsGet_account_feeCdc, map[string]*bintree{}}, "get_execution_effort_weights.cdc": {flowserviceaccountScriptsGet_execution_effort_weightsCdc, map[string]*bintree{}}, @@ -6755,6 +6754,7 @@ var _bintree = &bintree{nil, map[string]*bintree{ "get_is_account_creation_restricted.cdc": {flowserviceaccountScriptsGet_is_account_creation_restrictedCdc, map[string]*bintree{}}, "get_is_account_creator.cdc": {flowserviceaccountScriptsGet_is_account_creatorCdc, map[string]*bintree{}}, "get_tx_fee_parameters.cdc": {flowserviceaccountScriptsGet_tx_fee_parametersCdc, map[string]*bintree{}}, + "verify_payer_balance_for_tx_execution.cdc": {flowserviceaccountScriptsVerify_payer_balance_for_tx_executionCdc, map[string]*bintree{}}, }}, "set_execution_effort_weights.cdc": {flowserviceaccountSet_execution_effort_weightsCdc, map[string]*bintree{}}, "set_execution_memory_limit.cdc": {flowserviceaccountSet_execution_memory_limitCdc, map[string]*bintree{}}, diff --git a/lib/go/templates/service_templates.go b/lib/go/templates/service_templates.go index 1707cc439..1ec87e995 100644 --- a/lib/go/templates/service_templates.go +++ b/lib/go/templates/service_templates.go @@ -39,7 +39,7 @@ const ( getExecutionMemoryLimit = "FlowServiceAccount/scripts/get_execution_memory_limit.cdc" setExecutionMemoryLimit = "FlowServiceAccount/set_execution_memory_limit.cdc" - checkIfPayerHasSufficientBalance = "FlowServiceAccount/scripts/check_if_payer_has_sufficient_balance.cdc" + verifyPayerBalanceForTxExecution = "FlowServiceAccount/scripts/verify_payer_balance_for_tx_execution.cdc" ) // FlowToken Templates @@ -195,8 +195,8 @@ func GenerateGetExecutionMemoryLimit(env Environment) []byte { return []byte(ReplaceAddresses(code, env)) } -func GenerateCheckIfPayerHasSufficientBalance(env Environment) []byte { - code := assets.MustAssetString(checkIfPayerHasSufficientBalance) +func GenerateVerifyPayerBalanceForTxExecution(env Environment) []byte { + code := assets.MustAssetString(verifyPayerBalanceForTxExecution) return []byte(ReplaceAddresses(code, env)) } diff --git a/lib/go/test/service_test.go b/lib/go/test/service_test.go index 9b8acf50c..8094d233e 100644 --- a/lib/go/test/service_test.go +++ b/lib/go/test/service_test.go @@ -400,18 +400,19 @@ func TestContracts(t *testing.T) { }) t.Run("Should check if payer has sufficient balance to execute tx", func(t *testing.T) { - // TODO: Is it better to set up a mock tx and test against it? - - // TODO: What account should I use here? account := cadence.NewAddress(flow.HexToAddress(env.FlowFeesAddress)) - inclusionEffort := cadence.UFix64(1) - gasLimit := cadence.UFix64(99) + inclusionEffort := cadence.UFix64(999999999999999999) + gasLimit := cadence.UFix64(999999999999999999) args := [][]byte{jsoncdc.MustEncode(account), jsoncdc.MustEncode(inclusionEffort), jsoncdc.MustEncode(gasLimit)} - result = executeScriptAndCheck(t, b, templates.GenerateCheckIfPayerHasSufficientBalance(env), args) + result = executeScriptAndCheck(t, b, templates.GenerateVerifyPayerBalanceForTxExecution(env), args) require.NotNil(t, result) - require.True(t, result.(cadence.Bool).ToGoValue().(bool)) + + // parse VerifyPayerBalanceResult.canExecuteTransaction + resultStructValues := result.(cadence.Struct).GetFieldValues() + canExecuteTransaction := resultStructValues[0].ToGoValue().(bool) + require.True(t, canExecuteTransaction) }) // deploy the ServiceAccount contract diff --git a/transactions/FlowServiceAccount/scripts/check_if_payer_has_sufficient_balance.cdc b/transactions/FlowServiceAccount/scripts/verify_payer_balance_for_tx_execution.cdc similarity index 58% rename from transactions/FlowServiceAccount/scripts/check_if_payer_has_sufficient_balance.cdc rename to transactions/FlowServiceAccount/scripts/verify_payer_balance_for_tx_execution.cdc index b0261ad24..4aa05795a 100644 --- a/transactions/FlowServiceAccount/scripts/check_if_payer_has_sufficient_balance.cdc +++ b/transactions/FlowServiceAccount/scripts/verify_payer_balance_for_tx_execution.cdc @@ -1,8 +1,7 @@ import FlowFees from 0xFLOWFEESADDRESS -pub fun main(payerAcct: Address, inclusionEffort: UFix64, maxExecutionEffort: UFix64): Bool { +pub fun main(payerAcct: Address, inclusionEffort: UFix64, maxExecutionEffort: UFix64): FlowFees.VerifyPayerBalanceResult { let authAcct = getAuthAccount(payerAcct) - return FlowFees.verifyPayersBalanceForTransactionExecution(authAcct, - inclusionEffort: inclusionEffort, - maxExecutionEffort: maxExecutionEffort).canExecuteTransaction + return FlowFees.verifyPayersBalanceForTransactionExecution(authAcct, inclusionEffort: inclusionEffort, + maxExecutionEffort: maxExecutionEffort) } \ No newline at end of file From 5d81fb0db262aa82441119b8c95648f423b3e485 Mon Sep 17 00:00:00 2001 From: Illia Malachyn Date: Thu, 13 Jun 2024 12:04:39 +0300 Subject: [PATCH 3/7] Update contract to cadence 1 --- lib/go/templates/internal/assets/assets.go | 254 +----------------- lib/go/test/service_test.go | 5 +- .../verify_payer_balance_for_tx_execution.cdc | 6 +- 3 files changed, 9 insertions(+), 256 deletions(-) diff --git a/lib/go/templates/internal/assets/assets.go b/lib/go/templates/internal/assets/assets.go index 2441ccd45..383dfea4c 100644 --- a/lib/go/templates/internal/assets/assets.go +++ b/lib/go/templates/internal/assets/assets.go @@ -1,249 +1,5 @@ // Code generated by go-bindata. DO NOT EDIT. // sources: -<<<<<<< HEAD -// FlowServiceAccount/add_account_creator.cdc (565B) -// FlowServiceAccount/deposit_fees.cdc (838B) -// FlowServiceAccount/remove_account_creator.cdc (567B) -// FlowServiceAccount/scripts/get_account_creators.cdc (133B) -// FlowServiceAccount/scripts/get_account_fee.cdc (128B) -// FlowServiceAccount/scripts/get_execution_effort_weights.cdc (147B) -// FlowServiceAccount/scripts/get_execution_memory_limit.cdc (135B) -// FlowServiceAccount/scripts/get_execution_memory_weights.cdc (147B) -// FlowServiceAccount/scripts/get_fees_balance.cdc (102B) -// FlowServiceAccount/scripts/get_is_account_creation_restricted.cdc (137B) -// FlowServiceAccount/scripts/get_is_account_creator.cdc (149B) -// FlowServiceAccount/scripts/get_tx_fee_parameters.cdc (121B) -// FlowServiceAccount/scripts/verify_payer_balance_for_tx_execution.cdc (364B) -// FlowServiceAccount/set_execution_effort_weights.cdc (1.636kB) -// FlowServiceAccount/set_execution_memory_limit.cdc (260B) -// FlowServiceAccount/set_execution_memory_weights.cdc (288B) -// FlowServiceAccount/set_is_account_creation_restricted.cdc (586B) -// FlowServiceAccount/set_tx_fee_parameters.cdc (606B) -// FlowServiceAccount/set_tx_fee_surge_factor.cdc (465B) -// dkg/admin/force_stop_dkg.cdc (334B) -// dkg/admin/publish_participant.cdc (224B) -// dkg/admin/set_safe_threshold.cdc (425B) -// dkg/admin/start_dkg.cdc (366B) -// dkg/admin/stop_dkg.cdc (329B) -// dkg/create_participant.cdc (427B) -// dkg/scripts/get_consensus_nodes.cdc (103B) -// dkg/scripts/get_dkg_canonical_final_submission.cdc (98B) -// dkg/scripts/get_dkg_completed.cdc (99B) -// dkg/scripts/get_dkg_enabled.cdc (88B) -// dkg/scripts/get_final_submissions.cdc (106B) -// dkg/scripts/get_latest_whiteboard_messages.cdc (330B) -// dkg/scripts/get_node_final_submission.cdc (128B) -// dkg/scripts/get_node_has_submitted.cdc (116B) -// dkg/scripts/get_node_is_claimed.cdc (218B) -// dkg/scripts/get_node_is_registered.cdc (123B) -// dkg/scripts/get_submissions_count.cdc (114B) -// dkg/scripts/get_thresholds.cdc (408B) -// dkg/scripts/get_whiteboard_messages.cdc (115B) -// dkg/send_final_submission.cdc (412B) -// dkg/send_whiteboard_message.cdc (395B) -// epoch/admin/advance_view.cdc (649B) -// epoch/admin/calculate_rewards.cdc (361B) -// epoch/admin/deploy_epoch.cdc (1.173kB) -// epoch/admin/deploy_qc_dkg.cdc (295B) -// epoch/admin/pay_rewards.cdc (479B) -// epoch/admin/reset_epoch.cdc (1.648kB) -// epoch/admin/set_automatic_rewards.cdc (356B) -// epoch/admin/set_bonus_tokens.cdc (597B) -// epoch/admin/update_clusters.cdc (338B) -// epoch/admin/update_dkg_phase_views.cdc (328B) -// epoch/admin/update_epoch_config.cdc (1.755kB) -// epoch/admin/update_epoch_timing_config.cdc (483B) -// epoch/admin/update_epoch_views.cdc (329B) -// epoch/admin/update_reward.cdc (342B) -// epoch/admin/update_staking_views.cdc (331B) -// epoch/node/register_dkg_participant.cdc (531B) -// epoch/node/register_node.cdc (2.901kB) -// epoch/node/register_qc_voter.cdc (522B) -// epoch/scripts/get_bonus_tokens.cdc (102B) -// epoch/scripts/get_config_metadata.cdc (115B) -// epoch/scripts/get_create_clusters.cdc (197B) -// epoch/scripts/get_current_view.cdc (138B) -// epoch/scripts/get_epoch_counter.cdc (105B) -// epoch/scripts/get_epoch_metadata.cdc (154B) -// epoch/scripts/get_epoch_phase.cdc (111B) -// epoch/scripts/get_epoch_timing_config.cdc (129B) -// epoch/scripts/get_proposed_counter.cdc (108B) -// epoch/scripts/get_randomize.cdc (121B) -// epoch/scripts/get_target_end_time_for_epoch.cdc (258B) -// flowToken/burn_tokens.cdc (1.085kB) -// flowToken/create_forwarder.cdc (1.815kB) -// flowToken/mint_tokens.cdc (1.026kB) -// flowToken/scripts/get_balance.cdc (453B) -// flowToken/scripts/get_supply.cdc (207B) -// flowToken/setup_account.cdc (1.147kB) -// flowToken/transfer_tokens.cdc (1.301kB) -// idTableStaking/admin/add_approved_and_limits.cdc (1.606kB) -// idTableStaking/admin/add_approved_nodes.cdc (1.034kB) -// idTableStaking/admin/capability_end_epoch.cdc (1.355kB) -// idTableStaking/admin/change_candidate_limits.cdc (706B) -// idTableStaking/admin/change_cut.cdc (644B) -// idTableStaking/admin/change_del_minimums.cdc (669B) -// idTableStaking/admin/change_minimums.cdc (797B) -// idTableStaking/admin/change_payout.cdc (604B) -// idTableStaking/admin/end_epoch.cdc (892B) -// idTableStaking/admin/end_epoch_change_payout.cdc (958B) -// idTableStaking/admin/end_staking.cdc (677B) -// idTableStaking/admin/move_tokens.cdc (577B) -// idTableStaking/admin/pay_rewards.cdc (665B) -// idTableStaking/admin/remove_approved_nodes.cdc (990B) -// idTableStaking/admin/remove_invalid_nodes.cdc (676B) -// idTableStaking/admin/remove_node.cdc (608B) -// idTableStaking/admin/scale_rewards_test.cdc (716B) -// idTableStaking/admin/set_approved_nodes.cdc (607B) -// idTableStaking/admin/set_claimed.cdc (612B) -// idTableStaking/admin/set_node_weight.cdc (629B) -// idTableStaking/admin/set_non_operational.cdc (764B) -// idTableStaking/admin/set_open_access_node_slots.cdc (916B) -// idTableStaking/admin/set_slot_limits.cdc (1.551kB) -// idTableStaking/admin/start_staking.cdc (576B) -// idTableStaking/admin/transfer_admin.cdc (730B) -// idTableStaking/admin/transfer_fees_admin.cdc (409B) -// idTableStaking/admin/transfer_minter_deploy.cdc (1.305kB) -// idTableStaking/admin/upgrade_set_claimed.cdc (668B) -// idTableStaking/admin/upgrade_staking.cdc (156B) -// idTableStaking/delegation/del_request_unstaking.cdc (569B) -// idTableStaking/delegation/del_stake_new_tokens.cdc (842B) -// idTableStaking/delegation/del_stake_rewarded.cdc (575B) -// idTableStaking/delegation/del_stake_unstaked.cdc (575B) -// idTableStaking/delegation/del_withdraw_reward_tokens.cdc (850B) -// idTableStaking/delegation/del_withdraw_unstaked_tokens.cdc (850B) -// idTableStaking/delegation/delegator_add_capability.cdc (704B) -// idTableStaking/delegation/get_delegator_committed.cdc (315B) -// idTableStaking/delegation/get_delegator_info.cdc (293B) -// idTableStaking/delegation/get_delegator_info_from_address.cdc (511B) -// idTableStaking/delegation/get_delegator_request.cdc (324B) -// idTableStaking/delegation/get_delegator_rewarded.cdc (313B) -// idTableStaking/delegation/get_delegator_staked.cdc (309B) -// idTableStaking/delegation/get_delegator_unstaked.cdc (313B) -// idTableStaking/delegation/get_delegator_unstaking.cdc (315B) -// idTableStaking/delegation/get_delegator_unstaking_request.cdc (324B) -// idTableStaking/delegation/register_delegator.cdc (794B) -// idTableStaking/delegation/register_many_delegators.cdc (637B) -// idTableStaking/node/node_add_capability.cdc (711B) -// idTableStaking/node/register_many_nodes.cdc (1.082kB) -// idTableStaking/node/register_node.cdc (1.351kB) -// idTableStaking/node/request_unstake.cdc (551B) -// idTableStaking/node/stake_new_tokens.cdc (815B) -// idTableStaking/node/stake_rewarded_tokens.cdc (554B) -// idTableStaking/node/stake_unstaked_tokens.cdc (533B) -// idTableStaking/node/unstake_all.cdc (515B) -// idTableStaking/node/update_networking_address.cdc (556B) -// idTableStaking/node/withdraw_reward_tokens.cdc (828B) -// idTableStaking/node/withdraw_unstaked_tokens.cdc (828B) -// idTableStaking/scripts/get_approved_but_not_staked_nodes.cdc (664B) -// idTableStaking/scripts/get_approved_nodes.cdc (283B) -// idTableStaking/scripts/get_candidate_limits.cdc (265B) -// idTableStaking/scripts/get_candidate_nodes.cdc (228B) -// idTableStaking/scripts/get_current_table.cdc (190B) -// idTableStaking/scripts/get_cut_percentage.cdc (199B) -// idTableStaking/scripts/get_del_stake_requirements.cdc (218B) -// idTableStaking/scripts/get_delegators_below_min.cdc (1.88kB) -// idTableStaking/scripts/get_node_committed_tokens.cdc (257B) -// idTableStaking/scripts/get_node_info.cdc (234B) -// idTableStaking/scripts/get_node_info_from_address.cdc (477B) -// idTableStaking/scripts/get_node_initial_weight.cdc (245B) -// idTableStaking/scripts/get_node_networking_addr.cdc (253B) -// idTableStaking/scripts/get_node_networking_key.cdc (245B) -// idTableStaking/scripts/get_node_rewarded_tokens.cdc (258B) -// idTableStaking/scripts/get_node_role.cdc (225B) -// idTableStaking/scripts/get_node_staked_tokens.cdc (254B) -// idTableStaking/scripts/get_node_staking_key.cdc (239B) -// idTableStaking/scripts/get_node_total_commitment.cdc (273B) -// idTableStaking/scripts/get_node_total_commitment_without_delegators.cdc (276B) -// idTableStaking/scripts/get_node_type_ratio.cdc (235B) -// idTableStaking/scripts/get_node_unstaked_tokens.cdc (258B) -// idTableStaking/scripts/get_node_unstaking_request.cdc (269B) -// idTableStaking/scripts/get_node_unstaking_tokens.cdc (260B) -// idTableStaking/scripts/get_non_operational.cdc (205B) -// idTableStaking/scripts/get_proposed_table.cdc (192B) -// idTableStaking/scripts/get_role_counts.cdc (202B) -// idTableStaking/scripts/get_slot_limits.cdc (303B) -// idTableStaking/scripts/get_stake_requirements.cdc (241B) -// idTableStaking/scripts/get_table.cdc (184B) -// idTableStaking/scripts/get_total_staked.cdc (457B) -// idTableStaking/scripts/get_total_staked_by_type.cdc (250B) -// idTableStaking/scripts/get_weekly_payout.cdc (196B) -// inspect_field.cdc (122B) -// lockedTokens/admin/admin_create_shared_accounts.cdc (3.883kB) -// lockedTokens/admin/admin_deploy_contract.cdc (443B) -// lockedTokens/admin/admin_deposit_account_creator.cdc (856B) -// lockedTokens/admin/admin_remove_delegator.cdc (448B) -// lockedTokens/admin/check_main_registration.cdc (994B) -// lockedTokens/admin/check_shared_registration.cdc (630B) -// lockedTokens/admin/custody_create_account_with_lease_account.cdc (3.336kB) -// lockedTokens/admin/custody_create_only_lease_account.cdc (3.16kB) -// lockedTokens/admin/custody_create_only_shared_account.cdc (3.553kB) -// lockedTokens/admin/custody_create_shared_accounts.cdc (3.76kB) -// lockedTokens/admin/custody_setup_account_creator.cdc (643B) -// lockedTokens/admin/deposit_locked_tokens.cdc (1.663kB) -// lockedTokens/admin/get_unlocking_bad_accounts.cdc (472B) -// lockedTokens/admin/unlock_tokens.cdc (576B) -// lockedTokens/admin/unlock_tokens_for_multiple_accounts.cdc (2.78kB) -// lockedTokens/delegator/delegate_new_tokens.cdc (1.182kB) -// lockedTokens/delegator/delegate_rewarded_tokens.cdc (528B) -// lockedTokens/delegator/delegate_unstaked_tokens.cdc (520B) -// lockedTokens/delegator/get_delegator_id.cdc (434B) -// lockedTokens/delegator/get_delegator_info.cdc (1.464kB) -// lockedTokens/delegator/get_delegator_node_id.cdc (438B) -// lockedTokens/delegator/register_delegator.cdc (1.508kB) -// lockedTokens/delegator/request_unstaking.cdc (522B) -// lockedTokens/delegator/withdraw_rewarded_tokens.cdc (805B) -// lockedTokens/delegator/withdraw_rewarded_tokens_locked.cdc (528B) -// lockedTokens/delegator/withdraw_unstaked_tokens.cdc (528B) -// lockedTokens/staker/get_node_id.cdc (429B) -// lockedTokens/staker/get_staker_info.cdc (1.171kB) -// lockedTokens/staker/register_node.cdc (1.425kB) -// lockedTokens/staker/request_unstaking.cdc (522B) -// lockedTokens/staker/stake_new_tokens.cdc (1.234kB) -// lockedTokens/staker/stake_rewarded_tokens.cdc (525B) -// lockedTokens/staker/stake_unstaked_tokens.cdc (525B) -// lockedTokens/staker/unstake_all.cdc (488B) -// lockedTokens/staker/update_networking_address.cdc (482B) -// lockedTokens/staker/withdraw_rewarded_tokens.cdc (795B) -// lockedTokens/staker/withdraw_rewarded_tokens_locked.cdc (528B) -// lockedTokens/staker/withdraw_unstaked_tokens.cdc (528B) -// lockedTokens/user/deposit_tokens.cdc (713B) -// lockedTokens/user/get_locked_account_address.cdc (443B) -// lockedTokens/user/get_locked_account_balance.cdc (442B) -// lockedTokens/user/get_multiple_unlock_limits.cdc (560B) -// lockedTokens/user/get_total_balance.cdc (2.858kB) -// lockedTokens/user/get_unlock_limit.cdc (433B) -// lockedTokens/user/withdraw_tokens.cdc (713B) -// nodeVersionBeacon/admin/change_version_freeze_period.cdc (787B) -// nodeVersionBeacon/admin/delete_version_boundary.cdc (812B) -// nodeVersionBeacon/admin/heartbeat.cdc (612B) -// nodeVersionBeacon/admin/set_version_boundary.cdc (1.4kB) -// nodeVersionBeacon/scripts/get_current_node_version.cdc (236B) -// nodeVersionBeacon/scripts/get_current_node_version_as_string.cdc (263B) -// nodeVersionBeacon/scripts/get_next_version_boundary.cdc (267B) -// nodeVersionBeacon/scripts/get_next_version_update_sequence.cdc (206B) -// nodeVersionBeacon/scripts/get_version_boundaries.cdc (293B) -// nodeVersionBeacon/scripts/get_version_boundary_freeze_period.cdc (321B) -// quorumCertificate/admin/publish_voter.cdc (311B) -// quorumCertificate/admin/start_voting.cdc (1.495kB) -// quorumCertificate/admin/stop_voting.cdc (354B) -// quorumCertificate/create_voter.cdc (1.107kB) -// quorumCertificate/scripts/generate_quorum_certificate.cdc (321B) -// quorumCertificate/scripts/get_cluster.cdc (184B) -// quorumCertificate/scripts/get_cluster_complete.cdc (236B) -// quorumCertificate/scripts/get_cluster_node_weights.cdc (191B) -// quorumCertificate/scripts/get_cluster_vote_threshold.cdc (185B) -// quorumCertificate/scripts/get_cluster_votes.cdc (245B) -// quorumCertificate/scripts/get_cluster_weight.cdc (181B) -// quorumCertificate/scripts/get_clusters.cdc (265B) -// quorumCertificate/scripts/get_node_has_voted.cdc (480B) -// quorumCertificate/scripts/get_node_weight.cdc (315B) -// quorumCertificate/scripts/get_qc_enabled.cdc (101B) -// quorumCertificate/scripts/get_voter_is_registered.cdc (198B) -// quorumCertificate/scripts/get_voting_completed.cdc (187B) -// quorumCertificate/submit_vote.cdc (584B) -// randomBeaconHistory/scripts/get_backfiller_max_entries.cdc (285B) -======= // FlowServiceAccount/add_account_creator.cdc (588B) // FlowServiceAccount/deposit_fees.cdc (871B) // FlowServiceAccount/remove_account_creator.cdc (590B) @@ -256,6 +12,7 @@ // FlowServiceAccount/scripts/get_is_account_creation_restricted.cdc (145B) // FlowServiceAccount/scripts/get_is_account_creator.cdc (157B) // FlowServiceAccount/scripts/get_tx_fee_parameters.cdc (122B) +// FlowServiceAccount/scripts/verify_payer_balance_for_tx_execution.cdc (393B) // FlowServiceAccount/set_execution_effort_weights.cdc (1.663kB) // FlowServiceAccount/set_execution_memory_limit.cdc (287B) // FlowServiceAccount/set_execution_memory_weights.cdc (315B) @@ -484,7 +241,6 @@ // quorumCertificate/scripts/get_voting_completed.cdc (199B) // quorumCertificate/submit_vote.cdc (611B) // randomBeaconHistory/scripts/get_backfiller_max_entries.cdc (321B) ->>>>>>> master // randomBeaconHistory/scripts/get_latest_source_of_randomness.cdc (200B) // randomBeaconHistory/scripts/get_source_of_randomness.cdc (305B) // randomBeaconHistory/scripts/get_source_of_randomness_page.cdc (326B) @@ -848,8 +604,7 @@ func flowserviceaccountScriptsGet_tx_fee_parametersCdc() (*asset, error) { return a, nil } -<<<<<<< HEAD -var _flowserviceaccountScriptsVerify_payer_balance_for_tx_executionCdc = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x6c\x8f\x4d\x4b\xf4\x30\x14\x85\xf7\xfd\x15\x67\x39\x85\xf2\xf2\x2e\xc4\x45\xc1\x45\x65\x92\x95\xa0\x4c\xfd\x58\xc7\xcc\x8d\x06\xd2\xa4\xdc\xdc\x68\x07\xf1\xbf\x4b\xab\x63\xc1\x99\xec\x72\x12\x9e\xe7\x1c\x3f\x8c\x89\x05\x3a\xa4\x77\x4d\x94\xe1\x38\x0d\xf8\x3f\xe9\x9b\xdb\x27\xad\x54\xdf\x6d\xb7\x3b\xd5\xf7\x55\x35\x96\x67\xb8\x12\x31\x18\x1f\x37\xa3\x39\x10\x77\xd6\x4a\x8b\x6e\xbf\x67\xca\xb9\x81\x8f\x36\x94\xec\x53\x54\xce\x25\x96\x16\x0f\xda\x4f\x97\x17\x0d\x06\x33\xa9\x89\x6c\x91\x93\xb7\xba\xfd\xf5\xfe\x7b\x24\xf6\xee\x70\x37\x83\xaf\x4d\x30\xd1\xd2\x8e\x72\x09\x82\x8f\x0a\x00\x02\x09\x4c\x91\xd7\x59\x8a\x2b\xbc\x90\x74\xdf\xb7\x54\xa2\xac\x7d\xea\xe5\x33\x93\x14\x8e\x2b\xfb\x6d\x65\xe7\x1f\xb8\x4e\x7c\xcf\x26\x66\x63\x97\x5a\xc7\x7e\x9b\xa3\xe3\xcc\x9e\x3f\x41\xb3\xa8\xe6\x73\x6e\xe0\x69\x56\x57\x9f\x5f\x01\x00\x00\xff\xff\x84\x34\xe6\x41\x6c\x01\x00\x00" +var _flowserviceaccountScriptsVerify_payer_balance_for_tx_executionCdc = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x6c\x8f\x41\x4b\xc3\x40\x10\x85\xef\xf9\x15\x8f\x1e\x24\x0b\xc5\x93\x78\x08\x2a\xa4\xd0\x9c\x45\xb4\xf7\x61\x3b\xab\x0b\x9b\xdd\x32\x3b\x6b\x53\xc4\xff\x2e\x89\x8d\x01\xdb\xb9\xcd\x7b\xf0\xbe\xf7\x7c\x7f\x48\xa2\xe8\x42\x3a\x76\xcc\x19\x4e\x52\x8f\xd5\xfc\xae\xaa\x8a\xac\xe5\x9c\x6b\x0a\xc1\xc0\x95\x88\x9e\x7c\xac\x0f\x74\x62\x69\xad\xd5\x06\xed\x7e\x2f\x9c\xf3\x1a\x3e\xda\x50\xb2\x4f\x71\xeb\x5c\x12\x6d\xf0\xd6\xf9\xe1\xfe\x6e\x8d\x9e\x86\xed\xc0\xb6\xe8\x85\x67\x9a\x3f\xf0\xed\x8e\xc5\xbb\xd3\xf3\x18\xbc\xa1\x40\xd1\xf2\x0b\xe7\x12\x14\x5f\x15\x00\x04\x56\x50\xd1\x8f\x11\x8a\x47\xbc\xb3\xb6\xbf\x5f\x2a\x51\x1f\x46\xa7\xde\x24\x91\x74\xdc\x51\x28\x6c\x70\x73\xb6\x9e\x96\xae\x66\x0a\x12\xd6\x22\x71\xe1\x7e\x2e\xdc\x7c\x06\x77\x49\x5e\x85\x62\x26\x3b\x55\x9e\xbb\xd7\x33\xff\xca\xd6\x7f\xc2\x7a\x42\x8d\x77\x6d\xfc\xa5\x66\xaa\xef\x9f\x00\x00\x00\xff\xff\x99\x3a\x6b\x66\x89\x01\x00\x00" func flowserviceaccountScriptsVerify_payer_balance_for_tx_executionCdcBytes() ([]byte, error) { return bindataRead( @@ -865,14 +620,11 @@ func flowserviceaccountScriptsVerify_payer_balance_for_tx_executionCdc() (*asset } info := bindataFileInfo{name: "FlowServiceAccount/scripts/verify_payer_balance_for_tx_execution.cdc", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xd7, 0x8, 0x1f, 0x86, 0x15, 0x31, 0x41, 0xb4, 0x3, 0xf0, 0x3, 0x18, 0x37, 0xf1, 0xe6, 0xe3, 0xc5, 0xc4, 0xac, 0xcb, 0x53, 0xc0, 0x41, 0x2d, 0xb1, 0x45, 0xc8, 0x22, 0xe, 0x5c, 0xe4, 0x25}} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xbd, 0x3e, 0xca, 0x17, 0x78, 0xbc, 0xd8, 0xa, 0x19, 0x68, 0x60, 0xdb, 0xf6, 0xc8, 0x38, 0x98, 0x62, 0xb3, 0x8c, 0x21, 0x7f, 0xd3, 0x97, 0xfe, 0x76, 0x42, 0x28, 0x6b, 0xc9, 0xcf, 0x6a, 0x44}} return a, nil } -var _flowserviceaccountSet_execution_effort_weightsCdc = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x93\x5d\x6b\xe3\x3a\x10\x86\xef\xf3\x2b\x06\x9f\x9b\x14\xd2\x38\x4e\x62\x27\x36\x87\x03\xa5\xe7\x14\xca\xe9\xc2\xc2\x7e\x5d\x94\x2e\x1d\xcb\xe3\x58\x5b\x4b\xf2\x4a\x72\xd2\x10\xf2\xdf\x17\x59\x71\x9b\x7e\xb0\xec\x2e\x7b\xb1\x86\x48\x62\xde\x99\x47\x6f\x34\x52\x18\xc2\xfb\x8a\x1b\xb0\x1a\xa5\x41\x66\xb9\x92\x06\x0c\x59\x03\x92\x36\x40\xf7\xc4\x5a\x17\x03\x2a\x4b\xa5\x2d\x6c\x88\xaf\x2a\x6b\x06\x5d\x19\x81\xc0\x7b\x2e\x5a\xf1\x32\xaf\xe6\x82\x5b\x28\x95\x7e\x0a\xe6\x06\xb0\xde\xe0\xd6\x40\xea\xbe\x71\xcf\xf1\x58\x90\x28\xc8\x84\xbc\x30\xc0\x50\x42\x4e\x60\x88\x24\x54\xa4\x29\x73\x99\xee\x77\x0a\xd7\xe7\x58\x90\x64\x04\xe7\x4a\x34\xad\x45\x47\xfe\x9f\xcb\xe2\x66\x58\x59\xdb\x98\x2c\x0c\x57\xdc\x56\x6d\x3e\x66\x4a\x84\x4a\x96\xb5\xda\x84\xcc\x97\x84\x79\xad\xf2\x30\x99\x2c\x62\x2a\xe7\x4b\xb6\x60\x53\x9c\x24\x51\x31\x5d\xd0\x2c\xc9\x27\x69\x8c\xb4\x20\x16\xd3\x74\x32\x8f\x19\x2e\x42\xdd\x4a\xcb\x05\x85\x4c\x09\xa1\xa4\x9b\xfa\xfd\xee\xb8\x2c\xc6\x2b\xf5\xd7\xd5\x6c\x72\x72\x70\x75\xf1\xf1\xcd\xcf\x38\x72\xc3\xe9\x4a\x79\x47\x51\x51\xce\x67\x05\x2d\x63\x16\xe7\x8b\x38\x89\x96\x71\x14\xe1\xb2\xa4\x34\xa5\x34\x4d\x97\x98\x4f\x69\xce\x8a\x38\x0d\xcb\xb5\x08\x05\x59\xd2\x7e\xec\x2c\xa4\xce\x81\x37\x61\x2b\x02\x2e\x2d\x69\x89\x35\x34\x9a\x18\x37\xae\x27\xaa\xec\x94\x17\x4d\xea\x18\xae\x27\xd3\xcf\x51\x32\x82\x4d\xc5\x59\x05\x82\x50\xfa\x88\x53\xe8\x6b\x8b\x35\x58\x05\x11\xa8\xd6\xf6\x24\xab\x2c\xd6\xbe\x85\x2f\xa9\xb8\x46\x5e\x63\x5e\xbb\x34\xc0\xe3\xfe\x8f\x0f\x46\x5d\xc7\x0b\x2a\xb1\xad\x1f\x2e\x14\xa0\xef\xb1\xff\x1f\xcf\xce\xf1\x4a\xa9\x26\x83\xe8\x55\xed\x9d\x45\x4b\x82\xa4\xcd\x20\x82\x57\x33\x2e\x5a\xd9\xed\x7e\x29\xd7\x8a\x75\x51\xcf\x72\xc9\x4a\x03\x97\xd0\xa0\x46\x7f\x16\xa5\xd2\xa2\xb7\x71\x7b\x7b\xfb\xc5\x28\xe9\x96\xd7\x6e\x00\xd8\xf9\x09\x20\xb0\xdb\x86\x82\x0c\x82\x7f\x79\x87\x46\xbd\x0d\x46\x0f\xe2\x1a\xeb\xd6\xa9\xd7\x7d\xe4\xa8\xb2\x4b\xb8\xa3\x6d\x90\xc1\xee\x11\xf3\xe1\x52\xda\x64\x1e\x8c\x1e\x6b\x83\x68\x32\x89\x02\xd8\x8f\x9e\x14\xf6\xea\xf7\x4b\x93\x38\x9e\x25\x01\xec\x1f\x4b\x8f\x31\xbf\x64\x65\xfa\xe7\x58\x99\xfd\x3e\x2b\xfd\xf2\xc6\x2f\x7a\xec\x11\xe7\x2d\xda\xea\x98\xb2\x83\xa0\x50\x02\xb9\x74\xa2\xb1\x4a\xe3\x8a\x9c\xce\x0b\x92\x96\x97\x9c\xb4\x13\x1e\x9e\xc4\x7f\xdd\x8b\xf8\xe4\xaf\x78\x00\x7b\xbf\xe5\xcd\xe1\x76\x0d\x8e\x9e\xc6\x50\xd2\xe6\x90\x97\xc1\xce\xdb\xcf\xc0\xcf\xfb\x13\xd8\x0d\x9c\xcf\x46\x53\x83\x9a\x86\x86\xaf\x24\xe9\x0c\xce\x5a\x5b\x9d\x31\xa6\x5a\x69\xfb\x14\xf7\x79\x79\x5c\x2b\x2c\xfe\x7e\x8e\xfa\x67\x58\x6a\x25\x32\x08\x0f\xe6\xc3\xd7\xbd\x9e\x3c\x87\x19\x5c\xd3\x91\xc7\x11\x58\xf5\x83\x90\xfd\x60\xff\x2d\x00\x00\xff\xff\xad\xdd\x1d\x36\x64\x06\x00\x00" -======= var _flowserviceaccountSet_execution_effort_weightsCdc = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x93\x5f\x6b\xe3\x38\x14\xc5\xdf\xf3\x29\x2e\x5e\x58\x12\x48\xe3\x38\x89\x9d\xd8\x2c\x0b\x4b\x77\x0b\x65\xbb\xb0\xd0\xfd\xf3\x50\x3a\xf4\x5a\xbe\x8e\x35\xb5\x24\x8f\x24\x27\x0d\x21\xdf\x7d\x90\x15\xb7\xe9\x9f\x19\x66\x86\x79\x18\x43\x2c\xa1\x73\xee\xd1\x2f\xbe\x52\x18\xc2\x3f\x15\x37\x60\x35\x4a\x83\xcc\x72\x25\x0d\x18\xb2\x06\x24\x6d\x81\x1e\x88\xb5\x6e\x0d\xa8\x2c\x95\xb6\xb0\x25\xbe\xae\xac\x19\x74\x65\x04\x02\x1f\xb8\x68\xc5\x6b\x5f\xcd\x05\xb7\x50\x2a\xfd\x3c\x98\x1b\xc0\x7a\x8b\x3b\x03\xa9\x7b\x26\x7d\x8e\x8f\x05\x89\x82\x4c\xc8\x0b\x03\x0c\x25\xe4\x04\x86\x48\x42\x45\x9a\x32\xe7\x74\xbf\x33\xb8\x39\xc7\x82\x24\x23\x38\x57\xa2\x69\x2d\xba\xe4\x3f\xb9\x2c\x6e\x87\x95\xb5\x8d\xc9\xc2\x70\xcd\x6d\xd5\xe6\x13\xa6\x44\xa8\x64\x59\xab\x6d\xc8\x7c\x49\x98\xd7\x2a\x0f\x93\xe9\x32\xa6\x72\xb1\x62\x4b\x36\xc3\x69\x12\x15\xb3\x25\xcd\x93\x7c\x9a\xc6\x48\x4b\x62\x31\xcd\xa6\x8b\x98\xe1\x32\xd4\xad\xb4\x5c\x50\xc8\x94\x10\x4a\xba\xa1\xdf\xef\x9e\xcb\x62\xb2\x56\x3f\x5d\xcd\xa7\xa3\x23\xd5\xc5\x7f\x7f\x7d\x0d\x91\x7b\x9d\xad\x95\x27\x8a\x8a\x72\x31\x2f\x68\x15\xb3\x38\x5f\xc6\x49\xb4\x8a\xa3\x08\x57\x25\xa5\x29\xa5\x69\xba\xc2\x7c\x46\x0b\x56\xc4\x69\x58\x6e\x44\x28\xc8\x92\xf6\xef\x0e\x21\x75\x04\x1e\xc2\x56\x04\x5c\x5a\xd2\x12\x6b\x68\x34\x31\x6e\x5c\x4f\x54\xd9\x29\xaf\x9a\xd4\x65\xb8\x9e\xcc\xde\x45\xc9\x18\xb6\x15\x67\x15\x08\x42\xe9\x57\x9c\x42\x1f\x5a\xac\xc1\x2a\x88\x40\xb5\xb6\x4f\xb2\xca\x62\xed\x5b\xf8\x3a\x15\x37\xc8\x6b\xcc\x6b\x67\x03\x3c\xed\xff\xe4\x08\xea\x3a\x5e\x50\x89\x6d\xfd\x78\xa0\x00\x7d\x8f\xfd\xff\x78\xf1\x1d\xaf\x94\x6a\x32\x88\xde\xd4\xae\x2d\x5a\x12\x24\x6d\x06\x11\xbc\xe9\xb8\x68\x65\xb7\xfb\xa5\xdc\x28\xd6\xad\xfa\x2c\x67\x56\x1a\xb8\x84\x06\x35\xfa\x6f\x51\x2a\x2d\x7a\x8c\xbb\xbb\xbb\xf7\x46\x49\x37\xbd\x71\x2f\x80\xbd\x1f\x00\x02\xbb\x6b\x28\xc8\x20\xf8\x9d\x77\xd1\xa8\x77\xc1\xf8\x51\xdc\x60\xdd\x3a\xf5\xa6\x5f\x39\xa9\xec\x0c\xf7\xb4\x0b\x32\xd8\x3f\xc5\xfc\x7b\x29\x6d\xb2\x08\xc6\x4f\xb5\x41\x34\x9d\x46\x01\x1c\xc6\xcf\x0a\x7b\xf5\xf3\xa5\x49\x1c\xcf\x93\x00\x0e\x4f\xa5\xa7\x31\xdf\x84\x32\xfb\x71\x50\xe6\xdf\x0f\xa5\x9f\xde\xfa\x49\x1f\x7b\x92\xf3\x37\xda\xea\x34\x65\x0f\x41\xa1\x04\x72\xe9\x44\x63\x95\xc6\x35\x39\x9d\x17\x24\x2d\x2f\x39\x69\x27\x3c\x5e\x89\x3f\xba\x1b\xf1\xbf\x3f\xe2\x01\x1c\xfc\x96\xb7\xc7\xd3\x35\x38\xb9\x1a\x43\x49\xdb\xa3\x2f\x83\xbd\xc7\xcf\xc0\x8f\x87\x11\xec\x07\x8e\xb3\xd1\xd4\xa0\xa6\xa1\xe1\x6b\x49\x3a\x03\x6c\x6d\x35\xbc\xf6\x14\x23\xf8\xf9\x37\xc6\x54\x2b\x6d\xef\x76\x8f\x77\x4e\x8e\xa4\x93\x5a\x61\xf1\xcb\xcb\xf4\x5f\x87\xa5\x56\x22\x83\xf0\xe8\x0a\xdf\xc6\x1f\x7d\x2a\xd4\xe0\x86\x4e\xf0\xc7\x60\xd5\x17\x86\x1d\x06\x87\x8f\x01\x00\x00\xff\xff\x38\x5a\x8f\x3f\x7f\x06\x00\x00" ->>>>>>> master func flowserviceaccountSet_execution_effort_weightsCdcBytes() ([]byte, error) { return bindataRead( diff --git a/lib/go/test/service_test.go b/lib/go/test/service_test.go index bd7adb82f..a000c030d 100644 --- a/lib/go/test/service_test.go +++ b/lib/go/test/service_test.go @@ -412,8 +412,9 @@ func TestContracts(t *testing.T) { require.NotNil(t, result) // parse VerifyPayerBalanceResult.canExecuteTransaction - resultStructValues := result.(cadence.Struct).GetFieldValues() - canExecuteTransaction := resultStructValues[0].ToGoValue().(bool) + resultStruct := result.(cadence.Struct) + fields := cadence.FieldsMappedByName(resultStruct) + canExecuteTransaction := bool(fields["canExecuteTransaction"].(cadence.Bool)) require.True(t, canExecuteTransaction) }) diff --git a/transactions/FlowServiceAccount/scripts/verify_payer_balance_for_tx_execution.cdc b/transactions/FlowServiceAccount/scripts/verify_payer_balance_for_tx_execution.cdc index 4aa05795a..1594cc8b6 100644 --- a/transactions/FlowServiceAccount/scripts/verify_payer_balance_for_tx_execution.cdc +++ b/transactions/FlowServiceAccount/scripts/verify_payer_balance_for_tx_execution.cdc @@ -1,7 +1,7 @@ -import FlowFees from 0xFLOWFEESADDRESS +import FlowFees from "FlowFees" -pub fun main(payerAcct: Address, inclusionEffort: UFix64, maxExecutionEffort: UFix64): FlowFees.VerifyPayerBalanceResult { - let authAcct = getAuthAccount(payerAcct) +access(all) fun main(payerAcct: Address, inclusionEffort: UFix64, maxExecutionEffort: UFix64): FlowFees.VerifyPayerBalanceResult { + let authAcct = getAuthAccount(payerAcct) return FlowFees.verifyPayersBalanceForTransactionExecution(authAcct, inclusionEffort: inclusionEffort, maxExecutionEffort: maxExecutionEffort) } \ No newline at end of file From f19b797f0d0cd101bc554bcb527dc1ea5687373a Mon Sep 17 00:00:00 2001 From: Illia Malachyn Date: Thu, 13 Jun 2024 16:46:37 +0300 Subject: [PATCH 4/7] create custom minted account --- lib/go/test/service_test.go | 61 ++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/lib/go/test/service_test.go b/lib/go/test/service_test.go index a000c030d..f69029686 100644 --- a/lib/go/test/service_test.go +++ b/lib/go/test/service_test.go @@ -402,11 +402,64 @@ func TestContracts(t *testing.T) { }) t.Run("Should check if payer has sufficient balance to execute tx", func(t *testing.T) { - account := cadence.NewAddress(flow.HexToAddress(env.FlowFeesAddress)) - inclusionEffort := cadence.UFix64(999999999999999999) - gasLimit := cadence.UFix64(999999999999999999) + //TODO: it doesn't work, does it? + tx := createTxWithTemplateAndAuthorizer(b, + templates.GenerateChangeStorageFeeParametersScript(env), + storageFeesAddress) + + err = tx.AddArgument(CadenceUFix64("1.0")) + require.NoError(t, err) + err = tx.AddArgument(CadenceUFix64("4.0")) + require.NoError(t, err) + + signAndSubmit( + t, b, tx, + []flow.Address{storageFeesAddress}, + []crypto.Signer{storageFeesSigner}, + false, + ) + + assert.NoError(t, err) + _, err = b.CommitBlock() + assert.NoError(t, err) + + // create SmallBalanceContract contract + code := []byte(` + access(all) contract SmallBalanceContract { + access(all) let value: Int32 + + init() { + self.value = 42 + } + } + `) + keys := test.AccountKeyGenerator() + key, _ := keys.NewWithSigner() + address, err := adapter.CreateAccount(context.Background(), []*flow.AccountKey{key}, []sdktemplates.Contract{ + { + Name: "SmallBalanceContract", + Source: string(code), + }, + }) + + assert.NoError(t, err) + _, err = b.CommitBlock() + assert.NoError(t, err) + + // mint some flows to the account + mintTokensForAccount(t, b, env, address, "15.0") + + //TODO: remove this. this is for debug only + acc, err := adapter.GetAccount(context.Background(), address) + require.NotNil(t, acc) + require.NoError(t, err) + + // set up args + cadenceAddress := cadence.NewAddress(address) + inclusionEffort := cadence.UFix64(500) + gasLimit := cadence.UFix64(1) - args := [][]byte{jsoncdc.MustEncode(account), jsoncdc.MustEncode(inclusionEffort), jsoncdc.MustEncode(gasLimit)} + args := [][]byte{jsoncdc.MustEncode(cadenceAddress), jsoncdc.MustEncode(inclusionEffort), jsoncdc.MustEncode(gasLimit)} result = executeScriptAndCheck(t, b, templates.GenerateVerifyPayerBalanceForTxExecution(env), args) require.NotNil(t, result) From 305819d18db409a192e8413401ff2c695deb47e9 Mon Sep 17 00:00:00 2001 From: Illia Malachyn Date: Mon, 17 Jun 2024 15:15:38 +0300 Subject: [PATCH 5/7] payer executes tx and pays for it --- lib/go/test/service_test.go | 87 ++++++++++++++++++++++++------------- lib/go/test/test.go | 5 ++- 2 files changed, 61 insertions(+), 31 deletions(-) diff --git a/lib/go/test/service_test.go b/lib/go/test/service_test.go index f69029686..b024f6208 100644 --- a/lib/go/test/service_test.go +++ b/lib/go/test/service_test.go @@ -2,6 +2,7 @@ package test import ( "context" + "fmt" "testing" "github.com/onflow/cadence" @@ -47,10 +48,13 @@ func TestContracts(t *testing.T) { Source: string(storageFeesCode), }, }) + //mintTokensForAccount(t, b, env, storageFeesAddress, "0.00000001") assert.NoError(t, err) _, err = b.CommitBlock() assert.NoError(t, err) + mintTokensForAccount(t, b, env, storageFeesAddress, "10.0") + env.StorageFeesAddress = storageFeesAddress.String() t.Run("Should have initialized fields correctly", func(t *testing.T) { @@ -402,40 +406,23 @@ func TestContracts(t *testing.T) { }) t.Run("Should check if payer has sufficient balance to execute tx", func(t *testing.T) { - //TODO: it doesn't work, does it? - tx := createTxWithTemplateAndAuthorizer(b, - templates.GenerateChangeStorageFeeParametersScript(env), - storageFeesAddress) - - err = tx.AddArgument(CadenceUFix64("1.0")) - require.NoError(t, err) - err = tx.AddArgument(CadenceUFix64("4.0")) - require.NoError(t, err) - - signAndSubmit( - t, b, tx, - []flow.Address{storageFeesAddress}, - []crypto.Signer{storageFeesSigner}, - false, - ) - - assert.NoError(t, err) - _, err = b.CommitBlock() - assert.NoError(t, err) - // create SmallBalanceContract contract code := []byte(` access(all) contract SmallBalanceContract { - access(all) let value: Int32 + access(all) var value: Int32 init() { self.value = 42 } + + access(all) fun SetValue(new_value: Int32) { + self.value = new_value + } } `) keys := test.AccountKeyGenerator() - key, _ := keys.NewWithSigner() - address, err := adapter.CreateAccount(context.Background(), []*flow.AccountKey{key}, []sdktemplates.Contract{ + accKey, accSigner := keys.NewWithSigner() + accAddress, err := adapter.CreateAccount(context.Background(), []*flow.AccountKey{accKey}, []sdktemplates.Contract{ { Name: "SmallBalanceContract", Source: string(code), @@ -446,19 +433,53 @@ func TestContracts(t *testing.T) { _, err = b.CommitBlock() assert.NoError(t, err) + // we want to execute some tx so that the payer has less balance than default + txCode := []byte(fmt.Sprintf(` + import SmallBalanceContract from 0x%s + + transaction(value: Int32) { + prepare(signer: auth(Storage) &Account) {} + + execute { + if value > SmallBalanceContract.value { + SmallBalanceContract.SetValue(new_value: value + 1) + } else { + SmallBalanceContract.SetValue(new_value: value - 1) + } + } + } + `, accAddress)) + + tx := flow.NewTransaction(). + SetScript(txCode). + SetGasLimit(9999). + SetProposalKey(b.ServiceKey().Address, b.ServiceKey().Index, b.ServiceKey().SequenceNumber). + SetPayer(accAddress). + AddAuthorizer(accAddress) + + err = tx.AddArgument(cadence.Int32(15)) + require.NoError(t, err) + + txRes := signAndSubmit( + t, b, tx, + []flow.Address{accAddress}, + []crypto.Signer{accSigner}, + false, + ) + require.True(t, txRes.Succeeded()) + // mint some flows to the account - mintTokensForAccount(t, b, env, address, "15.0") + //mintTokensForAccount(t, b, env, accAddress, "15.0") //TODO: remove this. this is for debug only - acc, err := adapter.GetAccount(context.Background(), address) + acc, err := adapter.GetAccount(context.Background(), accAddress) require.NotNil(t, acc) require.NoError(t, err) // set up args - cadenceAddress := cadence.NewAddress(address) - inclusionEffort := cadence.UFix64(500) - gasLimit := cadence.UFix64(1) - + cadenceAddress := cadence.NewAddress(accAddress) + inclusionEffort := cadence.UFix64(20) + gasLimit := cadence.UFix64(9999) args := [][]byte{jsoncdc.MustEncode(cadenceAddress), jsoncdc.MustEncode(inclusionEffort), jsoncdc.MustEncode(gasLimit)} result = executeScriptAndCheck(t, b, templates.GenerateVerifyPayerBalanceForTxExecution(env), args) @@ -468,6 +489,12 @@ func TestContracts(t *testing.T) { resultStruct := result.(cadence.Struct) fields := cadence.FieldsMappedByName(resultStruct) canExecuteTransaction := bool(fields["canExecuteTransaction"].(cadence.Bool)) + + //TODO: remove this. this is for debug only + requiredBalance := uint64(fields["requiredBalance"].(cadence.UFix64)) + actualBalance := acc.Balance + println("req, act:", requiredBalance, actualBalance) + require.True(t, canExecuteTransaction) }) diff --git a/lib/go/test/test.go b/lib/go/test/test.go index ceb67c3d7..8273839ed 100644 --- a/lib/go/test/test.go +++ b/lib/go/test/test.go @@ -82,7 +82,10 @@ func newBlockchain(opts ...emulator.Option) (emulator.Emulator, *adapters.SDKAda append( []emulator.Option{ // No storage limit - emulator.WithStorageLimitEnabled(false), + emulator.WithStorageLimitEnabled(true), + emulator.WithTransactionFeesEnabled(true), + emulator.WithStorageLimitEnabled(true), + emulator.WithMinimumStorageReservation(cadence.UFix64(15000)), }, opts..., )..., From a680d2a897ecb59aa117c57f4682131b7ab61a1f Mon Sep 17 00:00:00 2001 From: Illia Malachyn Date: Mon, 24 Jun 2024 12:07:10 +0300 Subject: [PATCH 6/7] fix tx signers --- lib/go/test/service_test.go | 54 ++++++++++++++++++------------------- lib/go/test/test.go | 6 +---- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/lib/go/test/service_test.go b/lib/go/test/service_test.go index b024f6208..85cc14e3f 100644 --- a/lib/go/test/service_test.go +++ b/lib/go/test/service_test.go @@ -3,6 +3,7 @@ package test import ( "context" "fmt" + "github.com/onflow/flow-emulator/emulator" "testing" "github.com/onflow/cadence" @@ -48,13 +49,10 @@ func TestContracts(t *testing.T) { Source: string(storageFeesCode), }, }) - //mintTokensForAccount(t, b, env, storageFeesAddress, "0.00000001") assert.NoError(t, err) _, err = b.CommitBlock() assert.NoError(t, err) - mintTokensForAccount(t, b, env, storageFeesAddress, "10.0") - env.StorageFeesAddress = storageFeesAddress.String() t.Run("Should have initialized fields correctly", func(t *testing.T) { @@ -406,6 +404,13 @@ func TestContracts(t *testing.T) { }) t.Run("Should check if payer has sufficient balance to execute tx", func(t *testing.T) { + // create blockchain with tx fees enabled + blockchain, adapter := newBlockchain( + emulator.WithStorageLimitEnabled(true), + emulator.WithTransactionFeesEnabled(true), + emulator.WithStorageLimitEnabled(true), + emulator.WithMinimumStorageReservation(cadence.UFix64(15000))) + // create SmallBalanceContract contract code := []byte(` access(all) contract SmallBalanceContract { @@ -428,9 +433,8 @@ func TestContracts(t *testing.T) { Source: string(code), }, }) - assert.NoError(t, err) - _, err = b.CommitBlock() + _, err = blockchain.CommitBlock() assert.NoError(t, err) // we want to execute some tx so that the payer has less balance than default @@ -452,37 +456,30 @@ func TestContracts(t *testing.T) { tx := flow.NewTransaction(). SetScript(txCode). - SetGasLimit(9999). - SetProposalKey(b.ServiceKey().Address, b.ServiceKey().Index, b.ServiceKey().SequenceNumber). + SetComputeLimit(9999). + SetProposalKey(accAddress, 0, 0). SetPayer(accAddress). AddAuthorizer(accAddress) err = tx.AddArgument(cadence.Int32(15)) require.NoError(t, err) - txRes := signAndSubmit( - t, b, tx, - []flow.Address{accAddress}, - []crypto.Signer{accSigner}, - false, - ) - require.True(t, txRes.Succeeded()) - - // mint some flows to the account - //mintTokensForAccount(t, b, env, accAddress, "15.0") + err = tx.SignEnvelope(accAddress, 0, accSigner) + assert.NoError(t, err) - //TODO: remove this. this is for debug only - acc, err := adapter.GetAccount(context.Background(), accAddress) - require.NotNil(t, acc) - require.NoError(t, err) + // this transaction should fail and be reverted, but the fees will still be paid + // which will push the balance below the minimum account balance + // calling VerifyPayerBalanceForTxExecution after this will return false. + txRes := Submit(t, blockchain, tx, true) + require.True(t, txRes.Reverted()) // set up args cadenceAddress := cadence.NewAddress(accAddress) - inclusionEffort := cadence.UFix64(20) + inclusionEffort := cadence.UFix64(100_000_000) gasLimit := cadence.UFix64(9999) args := [][]byte{jsoncdc.MustEncode(cadenceAddress), jsoncdc.MustEncode(inclusionEffort), jsoncdc.MustEncode(gasLimit)} - result = executeScriptAndCheck(t, b, templates.GenerateVerifyPayerBalanceForTxExecution(env), args) + result = executeScriptAndCheck(t, blockchain, templates.GenerateVerifyPayerBalanceForTxExecution(env), args) require.NotNil(t, result) // parse VerifyPayerBalanceResult.canExecuteTransaction @@ -490,12 +487,16 @@ func TestContracts(t *testing.T) { fields := cadence.FieldsMappedByName(resultStruct) canExecuteTransaction := bool(fields["canExecuteTransaction"].(cadence.Bool)) - //TODO: remove this. this is for debug only + // actual balance should be less than required requiredBalance := uint64(fields["requiredBalance"].(cadence.UFix64)) + require.NotNil(t, requiredBalance) + + acc, err := adapter.GetAccount(context.Background(), accAddress) + require.NoError(t, err) actualBalance := acc.Balance - println("req, act:", requiredBalance, actualBalance) + require.Less(t, actualBalance, requiredBalance) - require.True(t, canExecuteTransaction) + require.False(t, canExecuteTransaction) }) // deploy the ServiceAccount contract @@ -511,5 +512,4 @@ func TestContracts(t *testing.T) { assert.NoError(t, err) _, err = b.CommitBlock() assert.NoError(t, err) - } diff --git a/lib/go/test/test.go b/lib/go/test/test.go index 8273839ed..77cdc41ca 100644 --- a/lib/go/test/test.go +++ b/lib/go/test/test.go @@ -81,11 +81,7 @@ func newBlockchain(opts ...emulator.Option) (emulator.Emulator, *adapters.SDKAda b, err := emulator.New( append( []emulator.Option{ - // No storage limit - emulator.WithStorageLimitEnabled(true), - emulator.WithTransactionFeesEnabled(true), - emulator.WithStorageLimitEnabled(true), - emulator.WithMinimumStorageReservation(cadence.UFix64(15000)), + emulator.WithStorageLimitEnabled(false), }, opts..., )..., From 1812579d3242d8c007ab47bd05c948c0df484bb4 Mon Sep 17 00:00:00 2001 From: Illia Malachyn Date: Mon, 24 Jun 2024 12:12:11 +0300 Subject: [PATCH 7/7] refactor test --- lib/go/test/service_test.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/go/test/service_test.go b/lib/go/test/service_test.go index 85cc14e3f..42faa8309 100644 --- a/lib/go/test/service_test.go +++ b/lib/go/test/service_test.go @@ -482,20 +482,23 @@ func TestContracts(t *testing.T) { result = executeScriptAndCheck(t, blockchain, templates.GenerateVerifyPayerBalanceForTxExecution(env), args) require.NotNil(t, result) - // parse VerifyPayerBalanceResult.canExecuteTransaction + // we want to get account balance later for comparison + acc, err := adapter.GetAccount(context.Background(), accAddress) + require.NoError(t, err) + + // parse VerifyPayerBalanceResult resultStruct := result.(cadence.Struct) fields := cadence.FieldsMappedByName(resultStruct) - canExecuteTransaction := bool(fields["canExecuteTransaction"].(cadence.Bool)) // actual balance should be less than required requiredBalance := uint64(fields["requiredBalance"].(cadence.UFix64)) require.NotNil(t, requiredBalance) - acc, err := adapter.GetAccount(context.Background(), accAddress) - require.NoError(t, err) actualBalance := acc.Balance require.Less(t, actualBalance, requiredBalance) + // user cannot execute tx as he does not have sufficient balance + canExecuteTransaction := bool(fields["canExecuteTransaction"].(cadence.Bool)) require.False(t, canExecuteTransaction) })