From 88f9236c61cf9e8dcf169d80a8aaa819c5d827bc Mon Sep 17 00:00:00 2001 From: antazoey Date: Thu, 2 Nov 2023 10:47:03 -0500 Subject: [PATCH] fix: issue where ape wouldn't recompile changed contracts [APE-1498] (#1720) --- src/ape/managers/project/manager.py | 4 ++- .../projects/script/contracts/contract.json | 1 + .../scripts/output_contract_view_methods.py | 16 +++++++++++ tests/integration/cli/test_compile.py | 1 + tests/integration/cli/test_run.py | 28 ++++++++++++++++++- 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 tests/integration/cli/projects/script/contracts/contract.json create mode 100644 tests/integration/cli/projects/script/scripts/output_contract_view_methods.py diff --git a/src/ape/managers/project/manager.py b/src/ape/managers/project/manager.py index c214a41afb..31a3dc4725 100644 --- a/src/ape/managers/project/manager.py +++ b/src/ape/managers/project/manager.py @@ -766,7 +766,9 @@ def _lookup_source(self, source_id: str) -> Optional[Source]: return None def _get_contract(self, name: str) -> Optional[ContractContainer]: - if name in self.contracts: + # NOTE: Use `load_contracts()` to re-compile changed contracts if needed. + # Else, if you make changes to a contract, it won't catch the need to re-compile. + if name in self.load_contracts(): return self.chain_manager.contracts.get_container(self.contracts[name]) return None diff --git a/tests/integration/cli/projects/script/contracts/contract.json b/tests/integration/cli/projects/script/contracts/contract.json new file mode 100644 index 0000000000..8326ea04a8 --- /dev/null +++ b/tests/integration/cli/projects/script/contracts/contract.json @@ -0,0 +1 @@ +{"abi":[{"anonymous":false,"inputs":[{"indexed":false,"name":"b","type":"bytes32"},{"indexed":false,"name":"prevNum","type":"uint256"},{"indexed":false,"name":"dynData","type":"string"},{"indexed":true,"name":"newNum","type":"uint256"},{"indexed":true,"name":"dynIndexed","type":"string"}],"name":"NumberChange","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"newAddress","type":"address"}],"name":"AddressChange","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"foo","type":"uint256"}],"name":"FooHappened","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"bar","type":"uint256"}],"name":"BarHappened","type":"event"},{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"fooAndBar","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"num","type":"uint256"}],"name":"setNumber","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_address","type":"address"}],"name":"setAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_address","type":"address"},{"name":"bal","type":"uint256"}],"name":"setBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getStruct","outputs":[{"components":[{"name":"a","type":"address"},{"name":"b","type":"bytes32"}],"name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNestedStruct1","outputs":[{"components":[{"components":[{"name":"a","type":"address"},{"name":"b","type":"bytes32"}],"name":"t","type":"tuple"},{"name":"foo","type":"uint256"}],"name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNestedStruct2","outputs":[{"components":[{"name":"foo","type":"uint256"},{"components":[{"name":"a","type":"address"},{"name":"b","type":"bytes32"}],"name":"t","type":"tuple"}],"name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNestedStructWithTuple1","outputs":[{"components":[{"components":[{"name":"a","type":"address"},{"name":"b","type":"bytes32"}],"name":"t","type":"tuple"},{"name":"foo","type":"uint256"}],"name":"","type":"tuple"},{"name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNestedStructWithTuple2","outputs":[{"name":"","type":"uint256"},{"components":[{"name":"foo","type":"uint256"},{"components":[{"name":"a","type":"address"},{"name":"b","type":"bytes32"}],"name":"t","type":"tuple"}],"name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getStructWithArray","outputs":[{"components":[{"name":"foo","type":"uint256"},{"components":[{"name":"a","type":"address"},{"name":"b","type":"bytes32"}],"name":"arr","type":"tuple[2]"},{"name":"bar","type":"uint256"}],"name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getEmptyArray","outputs":[{"name":"","type":"uint256[]"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"getSingleItemArray","outputs":[{"name":"","type":"uint256[]"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"getFilledArray","outputs":[{"name":"","type":"uint256[]"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"getAddressArray","outputs":[{"name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getDynamicStructArray","outputs":[{"components":[{"components":[{"name":"a","type":"address"},{"name":"b","type":"bytes32"}],"name":"t","type":"tuple"},{"name":"foo","type":"uint256"}],"name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getStaticStructArray","outputs":[{"components":[{"name":"foo","type":"uint256"},{"components":[{"name":"a","type":"address"},{"name":"b","type":"bytes32"}],"name":"t","type":"tuple"}],"name":"","type":"tuple[2]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getArrayWithBiggerSize","outputs":[{"name":"","type":"uint256[20]"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"getTupleOfArrays","outputs":[{"name":"","type":"uint256[20]"},{"name":"","type":"uint256[20]"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"getMultipleValues","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"getUnnamedTuple","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"getTupleOfAddressArray","outputs":[{"name":"","type":"address[20]"},{"name":"","type":"uint128[20]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNestedArrayFixedFixed","outputs":[{"name":"","type":"uint256[2][3]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNestedArrayDynamicFixed","outputs":[{"name":"","type":"uint256[2][]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNestedArrayFixedDynamic","outputs":[{"name":"","type":"uint256[][3]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNestedArrayMixedDynamic","outputs":[{"name":"","type":"uint256[][3][][5]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNestedAddressArray","outputs":[{"name":"","type":"address[3][]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"myNumber","outputs":[{"name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"prevNumber","outputs":[{"name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"theAddress","outputs":[{"name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"name":"arg0","type":"address"}],"name":"balances","outputs":[{"name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"name":"arg0","type":"uint256"},{"name":"arg1","type":"uint256"}],"name":"dynArray","outputs":[{"name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"name":"arg0","type":"uint256"},{"name":"arg1","type":"uint256"},{"name":"arg2","type":"uint256"},{"name":"arg3","type":"uint256"}],"name":"mixedArray","outputs":[{"name":"","type":"uint256"}],"stateMutability":"view","type":"function"}],"contractName":"TestContractVy","deploymentBytecode":{"bytecode":"0x34611694573360005560016005556000600655600261040655600061040755600161040855600361080755600061080855600161080955600261080a55610c08546103ff81116116945760018101610c0855610c038102610c09016005548082558060051b60018301600082601f0160051c610400811161169457801561009657905b806006015481840155600101818118610082575b505050505061040654806104018301558060051b6001610401840101600082601f0160051c61040081116116945780156100e157905b806104070154818401556001018181186100cc575b505050505061080754806108028301558060051b6001610802840101600082601f0160051c610400811161169457801561012c57905b80610808015481840155600101818118610117575b5050505050505062301809546103ff811161169457600181016230180955610c0381026230180a016005548082558060051b60018301600082601f0160051c610400811161169457801561019057905b80600601548184015560010181811861017c575b505050505061040654806104018301558060051b6001610401840101600082601f0160051c61040081116116945780156101db57905b806104070154818401556001018181186101c6575b505050505061080754806108028301558060051b6001610802840101600082601f0160051c610400811161169457801561022657905b80610808015481840155600101818118610211575b5050505050505062301809546103ff811161169457600181016230180955610c0381026230180a016005548082558060051b60018301600082601f0160051c610400811161169457801561028a57905b806006015481840155600101818118610276575b505050505061040654806104018301558060051b6001610401840101600082601f0160051c61040081116116945780156102d557905b806104070154818401556001018181186102c0575b505050505061080754806108028301558060051b6001610802840101600082601f0160051c610400811161169457801561032057905b8061080801548184015560010181811861030b575b5050505050505061135a6103396100003961135a610000f36003361161000c57611342565b60003560e01c3461134857632beb1711811861007c57600436186113485760007f1a7c56fae0af54ebae73bc4699b9de9835e7bb86b050dff7e80695b633f17abd60006040a260017fe5299d63f5ecdd1740024ea0902bd82cc8dc6b51d69078e007096f907615ced560006040a2005b633fb5c1cb81186101e95760243618611348576000543318156100f657600b6040527f21617574686f72697a656400000000000000000000000000000000000000000060605260405060405180606001601f826000031636823750506308c379a06000526020602052601f19601f6040510116604401601cfd5b6005600435146113485760015460025560043560015560076080527f44796e616d69630000000000000000000000000000000000000000000000000060a05260808051602082012090506004357fa84473122c11e32cd505595f246a28418b8ecd6cf819f4e3915363fad1b8f9686060600143034060c05260025460e052806101005260076040527f44796e616d69630000000000000000000000000000000000000000000000000060605260408160c00181518082526020830160208301815181525050508051806020830101601f82600003163682375050601f19601f82516020010116905090508101905060c0a3005b63e30081a0811861023b5760243618611348576004358060a01c611348576040526040516003556040517f7ff7bacc6cd661809ed1ddce28d4ad2c5b37779b61b9e3235f8262be529101a960006060a2005b63e30443bc81186102845760443618611348576004358060a01c611348576040526004604051602052600052604060002080546024358082018281106113485790509050815550005b6309b1b3f281186102a957600436186113485733604052600143034060605260406040f35b6302f487d681186102d3576004361861134857336040526001430340606052600160805260606040f35b63a420b5a581186102fd576004361861134857600260405233606052600143034060805260606040f35b63e9f7fd14811861032c5760043618611348573360405260014303406060526001608052600160a05260806040f35b63a2fbee53811861035b5760043618611348576002604052600260605233608052600143034060a05260806040f35b6342ce1ec6811861039657600436186113485760016040523360605260014303406080523360a052600143034060c052600260e05260c06040f35b63052f3e7681186103f957600436186113485760208060405280604001600060008252600060006000600181116113485780156103e657905b60008160051b6020870101526001018181186103cf575b5050810160200190509050810190506040f35b63b345ad968118610474576004361861134857602080604052806040016000600160a052600160c052600060a0518084528060051b6000826001811161134857801561045e57905b8060051b60c001518160051b602089010152600101818118610441575b5050820160200191505090509050810190506040f35b6335417bf481186104fd576004361861134857602080604052806040016000600360e052600161010052600261012052600361014052600060e0518084528060051b600082600381116113485780156104e757905b8060051b61010001518160051b6020890101526001018181186104c9575b5050820160200191505090509050810190506040f35b63a5b0930d811861057c576004361861134857602080604052806040016000600260c0523360e0523361010052600060c0518084528060051b6000826002811161134857801561056657905b8060051b60e001518160051b602089010152600101818118610549575b5050820160200191505090509050810190506040f35b639bfb2ad88118610635576004361861134857602080604052806040016000600261014052336101605260014303406101805260016101a052336101c05260014303406101e052600261020052600061014051808452606081026000826002811161134857801561061f57905b606081026020880101606082026101600180518252602081015160208301526040810151604083015250506001018181186105e9575b5050820160200191505090509050810190506040f35b633ce80e9481186106705760043618611348576001604052336060526001430340608052600260a0523360c052600143034060e05260c06040f35b6343790b648118610691576004361861134857610280366040376102806040f35b63d4d64b3581186106b2576004361861134857610500366040376105006040f35b63650543a381186106d6576004361861134857607b60405261014160605260406040f35b63243e096381186106f557600436186113485760403660403760406040f35b638ba6052d81186107bd57600436186113485761028036604037336040526040516102c0526060516102e0526080516103005260a0516103205260c0516103405260e051610360526101005161038052610120516103a052610140516103c052610160516103e05261018051610400526101a051610420526101c051610440526101e051610460526102005161048052610220516104a052610240516104c052610260516104e05261028051610500526102a0516105205261028036610540376105006102c0f35b63ccd62aa481186107f4576004361861134857600160405260026060526003608052600460a052600560c052600660e05260c06040f35b636126c87f81186108a9576004361861134857602080604052806040016000600362010080526001620100a0526002620100c0526003620100e052600462010100526005620101205260066201014052600062010080518084528060061b600082610400811161134857801561089357905b8060061b60208801018160061b620100a00180518252602081015160208301525050600101818118610866575b5050820160200191505090509050810190506040f35b6394a66fc981186109cc57600436186113485760208060405280604001606080825280820160006005548083528060051b600082610400811161134857801561090857905b80600601548160051b6020880101526001018181186108ee575b505082016020019150509050810190508060208301528082016000610406548083528060051b600082610400811161134857801561095d57905b8061040701548160051b602088010152600101818118610942575b505082016020019150509050810190508060408301528082016000610807548083528060051b60008261040081116113485780156109b257905b8061080801548160051b602088010152600101818118610997575b505082016020019150509050810190509050810190506040f35b63abeb2022811861112a5760043618611348576020806040528060400160a08082528082016000610c08548083528060051b6000826104008111611348578015610b4857905b828160051b602088010152610c038102610c09018360208801016060808252808201600084548083528060051b6000826104008111611348578015610a6f57905b8060018a0101548160051b602088010152600101818118610a53575b505082016020019150509050810190508060208301526104018301818301600082548083528060051b6000826104008111611348578015610ac857905b806001880101548160051b602088010152600101818118610aac575b5050820160200191505090509050810190508060408301526108028301818301600082548083528060051b6000826104008111611348578015610b2357905b806001880101548160051b602088010152600101818118610b07575b5050820160200191505090509050810190509050905083019250600101818118610a12575b50508201602001915050905081019050806020830152808201600062301809548083528060051b6000826104008111611348578015610cba57905b828160051b602088010152610c0381026230180a018360208801016060808252808201600084548083528060051b6000826104008111611348578015610be157905b8060018a0101548160051b602088010152600101818118610bc5575b505082016020019150509050810190508060208301526104018301818301600082548083528060051b6000826104008111611348578015610c3a57905b806001880101548160051b602088010152600101818118610c1e575b5050820160200191505090509050810190508060408301526108028301818301600082548083528060051b6000826104008111611348578015610c9557905b806001880101548160051b602088010152600101818118610c79575b5050820160200191505090509050810190509050905083019250600101818118610b83575b5050820160200191505090508101905080604083015280820160006260240a548083528060051b6000826104008111611348578015610e2c57905b828160051b602088010152610c0381026260240b018360208801016060808252808201600084548083528060051b6000826104008111611348578015610d5357905b8060018a0101548160051b602088010152600101818118610d37575b505082016020019150509050810190508060208301526104018301818301600082548083528060051b6000826104008111611348578015610dac57905b806001880101548160051b602088010152600101818118610d90575b5050820160200191505090509050810190508060408301526108028301818301600082548083528060051b6000826104008111611348578015610e0757905b806001880101548160051b602088010152600101818118610deb575b5050820160200191505090509050810190509050905083019250600101818118610cf5575b5050820160200191505090508101905080606083015280820160006290300b548083528060051b6000826104008111611348578015610f9e57905b828160051b602088010152610c0381026290300c018360208801016060808252808201600084548083528060051b6000826104008111611348578015610ec557905b8060018a0101548160051b602088010152600101818118610ea9575b505082016020019150509050810190508060208301526104018301818301600082548083528060051b6000826104008111611348578015610f1e57905b806001880101548160051b602088010152600101818118610f02575b5050820160200191505090509050810190508060408301526108028301818301600082548083528060051b6000826104008111611348578015610f7957905b806001880101548160051b602088010152600101818118610f5d575b5050820160200191505090509050810190509050905083019250600101818118610e67575b50508201602001915050905081019050806080830152808201600062c03c0c548083528060051b600082610400811161134857801561111057905b828160051b602088010152610c03810262c03c0d018360208801016060808252808201600084548083528060051b600082610400811161134857801561103757905b8060018a0101548160051b60208801015260010181811861101b575b505082016020019150509050810190508060208301526104018301818301600082548083528060051b600082610400811161134857801561109057905b806001880101548160051b602088010152600101818118611074575b5050820160200191505090509050810190508060408301526108028301818301600082548083528060051b60008261040081116113485780156110eb57905b806001880101548160051b6020880101526001018181186110cf575b5050820160200191505090509050810190509050905083019250600101818118610fd9575b505082016020019150509050810190509050810190506040f35b6399e74a4c81186111d95760043618611348576020806040528060400160006002620180805233620180a05233620180c05233620180e0526060366201810037600062018080518084526060810260008261040081116113485780156111c357905b60608102602088010160608202620180a001805182526020810151602083015260408101516040830152505060010181811861118c575b5050820160200191505090509050810190506040f35b638da5cb5b81186111f857600436186113485760005460405260206040f35b6323fd0e40811861121757600436186113485760015460405260206040f35b634825cf6f811861123657600436186113485760025460405260206040f35b636cbceeec811861125557600436186113485760035460405260206040f35b6327e235e381186112905760243618611348576004358060a01c61134857604052600460405160205260005260406000205460605260206060f35b63d3aaff6d81186112d2576044361861134857610401600435600281116113485702600501602435815481101561134857600182010190505460405260206040f35b63ae8ef2cb811861134057608436186113485762300c01600435600481116113485702610c0801610c03602435825481101561134857026001820101905061040160443560028111611348570281019050606435815481101561134857600182010190505460405260206040f35b505b60006000fd5b600080fda165767970657283000306000b005b600080fd"},"devdoc":{},"runtimeBytecode":{"bytecode":"0x6003361161000c57611342565b60003560e01c3461134857632beb1711811861007c57600436186113485760007f1a7c56fae0af54ebae73bc4699b9de9835e7bb86b050dff7e80695b633f17abd60006040a260017fe5299d63f5ecdd1740024ea0902bd82cc8dc6b51d69078e007096f907615ced560006040a2005b633fb5c1cb81186101e95760243618611348576000543318156100f657600b6040527f21617574686f72697a656400000000000000000000000000000000000000000060605260405060405180606001601f826000031636823750506308c379a06000526020602052601f19601f6040510116604401601cfd5b6005600435146113485760015460025560043560015560076080527f44796e616d69630000000000000000000000000000000000000000000000000060a05260808051602082012090506004357fa84473122c11e32cd505595f246a28418b8ecd6cf819f4e3915363fad1b8f9686060600143034060c05260025460e052806101005260076040527f44796e616d69630000000000000000000000000000000000000000000000000060605260408160c00181518082526020830160208301815181525050508051806020830101601f82600003163682375050601f19601f82516020010116905090508101905060c0a3005b63e30081a0811861023b5760243618611348576004358060a01c611348576040526040516003556040517f7ff7bacc6cd661809ed1ddce28d4ad2c5b37779b61b9e3235f8262be529101a960006060a2005b63e30443bc81186102845760443618611348576004358060a01c611348576040526004604051602052600052604060002080546024358082018281106113485790509050815550005b6309b1b3f281186102a957600436186113485733604052600143034060605260406040f35b6302f487d681186102d3576004361861134857336040526001430340606052600160805260606040f35b63a420b5a581186102fd576004361861134857600260405233606052600143034060805260606040f35b63e9f7fd14811861032c5760043618611348573360405260014303406060526001608052600160a05260806040f35b63a2fbee53811861035b5760043618611348576002604052600260605233608052600143034060a05260806040f35b6342ce1ec6811861039657600436186113485760016040523360605260014303406080523360a052600143034060c052600260e05260c06040f35b63052f3e7681186103f957600436186113485760208060405280604001600060008252600060006000600181116113485780156103e657905b60008160051b6020870101526001018181186103cf575b5050810160200190509050810190506040f35b63b345ad968118610474576004361861134857602080604052806040016000600160a052600160c052600060a0518084528060051b6000826001811161134857801561045e57905b8060051b60c001518160051b602089010152600101818118610441575b5050820160200191505090509050810190506040f35b6335417bf481186104fd576004361861134857602080604052806040016000600360e052600161010052600261012052600361014052600060e0518084528060051b600082600381116113485780156104e757905b8060051b61010001518160051b6020890101526001018181186104c9575b5050820160200191505090509050810190506040f35b63a5b0930d811861057c576004361861134857602080604052806040016000600260c0523360e0523361010052600060c0518084528060051b6000826002811161134857801561056657905b8060051b60e001518160051b602089010152600101818118610549575b5050820160200191505090509050810190506040f35b639bfb2ad88118610635576004361861134857602080604052806040016000600261014052336101605260014303406101805260016101a052336101c05260014303406101e052600261020052600061014051808452606081026000826002811161134857801561061f57905b606081026020880101606082026101600180518252602081015160208301526040810151604083015250506001018181186105e9575b5050820160200191505090509050810190506040f35b633ce80e9481186106705760043618611348576001604052336060526001430340608052600260a0523360c052600143034060e05260c06040f35b6343790b648118610691576004361861134857610280366040376102806040f35b63d4d64b3581186106b2576004361861134857610500366040376105006040f35b63650543a381186106d6576004361861134857607b60405261014160605260406040f35b63243e096381186106f557600436186113485760403660403760406040f35b638ba6052d81186107bd57600436186113485761028036604037336040526040516102c0526060516102e0526080516103005260a0516103205260c0516103405260e051610360526101005161038052610120516103a052610140516103c052610160516103e05261018051610400526101a051610420526101c051610440526101e051610460526102005161048052610220516104a052610240516104c052610260516104e05261028051610500526102a0516105205261028036610540376105006102c0f35b63ccd62aa481186107f4576004361861134857600160405260026060526003608052600460a052600560c052600660e05260c06040f35b636126c87f81186108a9576004361861134857602080604052806040016000600362010080526001620100a0526002620100c0526003620100e052600462010100526005620101205260066201014052600062010080518084528060061b600082610400811161134857801561089357905b8060061b60208801018160061b620100a00180518252602081015160208301525050600101818118610866575b5050820160200191505090509050810190506040f35b6394a66fc981186109cc57600436186113485760208060405280604001606080825280820160006005548083528060051b600082610400811161134857801561090857905b80600601548160051b6020880101526001018181186108ee575b505082016020019150509050810190508060208301528082016000610406548083528060051b600082610400811161134857801561095d57905b8061040701548160051b602088010152600101818118610942575b505082016020019150509050810190508060408301528082016000610807548083528060051b60008261040081116113485780156109b257905b8061080801548160051b602088010152600101818118610997575b505082016020019150509050810190509050810190506040f35b63abeb2022811861112a5760043618611348576020806040528060400160a08082528082016000610c08548083528060051b6000826104008111611348578015610b4857905b828160051b602088010152610c038102610c09018360208801016060808252808201600084548083528060051b6000826104008111611348578015610a6f57905b8060018a0101548160051b602088010152600101818118610a53575b505082016020019150509050810190508060208301526104018301818301600082548083528060051b6000826104008111611348578015610ac857905b806001880101548160051b602088010152600101818118610aac575b5050820160200191505090509050810190508060408301526108028301818301600082548083528060051b6000826104008111611348578015610b2357905b806001880101548160051b602088010152600101818118610b07575b5050820160200191505090509050810190509050905083019250600101818118610a12575b50508201602001915050905081019050806020830152808201600062301809548083528060051b6000826104008111611348578015610cba57905b828160051b602088010152610c0381026230180a018360208801016060808252808201600084548083528060051b6000826104008111611348578015610be157905b8060018a0101548160051b602088010152600101818118610bc5575b505082016020019150509050810190508060208301526104018301818301600082548083528060051b6000826104008111611348578015610c3a57905b806001880101548160051b602088010152600101818118610c1e575b5050820160200191505090509050810190508060408301526108028301818301600082548083528060051b6000826104008111611348578015610c9557905b806001880101548160051b602088010152600101818118610c79575b5050820160200191505090509050810190509050905083019250600101818118610b83575b5050820160200191505090508101905080604083015280820160006260240a548083528060051b6000826104008111611348578015610e2c57905b828160051b602088010152610c0381026260240b018360208801016060808252808201600084548083528060051b6000826104008111611348578015610d5357905b8060018a0101548160051b602088010152600101818118610d37575b505082016020019150509050810190508060208301526104018301818301600082548083528060051b6000826104008111611348578015610dac57905b806001880101548160051b602088010152600101818118610d90575b5050820160200191505090509050810190508060408301526108028301818301600082548083528060051b6000826104008111611348578015610e0757905b806001880101548160051b602088010152600101818118610deb575b5050820160200191505090509050810190509050905083019250600101818118610cf5575b5050820160200191505090508101905080606083015280820160006290300b548083528060051b6000826104008111611348578015610f9e57905b828160051b602088010152610c0381026290300c018360208801016060808252808201600084548083528060051b6000826104008111611348578015610ec557905b8060018a0101548160051b602088010152600101818118610ea9575b505082016020019150509050810190508060208301526104018301818301600082548083528060051b6000826104008111611348578015610f1e57905b806001880101548160051b602088010152600101818118610f02575b5050820160200191505090509050810190508060408301526108028301818301600082548083528060051b6000826104008111611348578015610f7957905b806001880101548160051b602088010152600101818118610f5d575b5050820160200191505090509050810190509050905083019250600101818118610e67575b50508201602001915050905081019050806080830152808201600062c03c0c548083528060051b600082610400811161134857801561111057905b828160051b602088010152610c03810262c03c0d018360208801016060808252808201600084548083528060051b600082610400811161134857801561103757905b8060018a0101548160051b60208801015260010181811861101b575b505082016020019150509050810190508060208301526104018301818301600082548083528060051b600082610400811161134857801561109057905b806001880101548160051b602088010152600101818118611074575b5050820160200191505090509050810190508060408301526108028301818301600082548083528060051b60008261040081116113485780156110eb57905b806001880101548160051b6020880101526001018181186110cf575b5050820160200191505090509050810190509050905083019250600101818118610fd9575b505082016020019150509050810190509050810190506040f35b6399e74a4c81186111d95760043618611348576020806040528060400160006002620180805233620180a05233620180c05233620180e0526060366201810037600062018080518084526060810260008261040081116113485780156111c357905b60608102602088010160608202620180a001805182526020810151602083015260408101516040830152505060010181811861118c575b5050820160200191505090509050810190506040f35b638da5cb5b81186111f857600436186113485760005460405260206040f35b6323fd0e40811861121757600436186113485760015460405260206040f35b634825cf6f811861123657600436186113485760025460405260206040f35b636cbceeec811861125557600436186113485760035460405260206040f35b6327e235e381186112905760243618611348576004358060a01c61134857604052600460405160205260005260406000205460605260206060f35b63d3aaff6d81186112d2576044361861134857610401600435600281116113485702600501602435815481101561134857600182010190505460405260206040f35b63ae8ef2cb811861134057608436186113485762300c01600435600481116113485702610c0801610c03602435825481101561134857026001820101905061040160443560028111611348570281019050606435815481101561134857600182010190505460405260206040f35b505b60006000fd5b600080fda165767970657283000306000b"},"sourceId":"TestContractVy.vy","userdoc":{}} diff --git a/tests/integration/cli/projects/script/scripts/output_contract_view_methods.py b/tests/integration/cli/projects/script/scripts/output_contract_view_methods.py new file mode 100644 index 0000000000..8ebcb1d188 --- /dev/null +++ b/tests/integration/cli/projects/script/scripts/output_contract_view_methods.py @@ -0,0 +1,16 @@ +import click + +import ape + +""" +Part of test that makes sure a contract is re-compiled +before running the script. The test changes a view method +and asserts the changed method's name appears in the script +output. +""" + + +def main(): + contract = ape.project.TestContractVy + for method in contract.contract_type.view_methods: + click.echo(method.name) diff --git a/tests/integration/cli/test_compile.py b/tests/integration/cli/test_compile.py index c2a2af1446..03fe81fd81 100644 --- a/tests/integration/cli/test_compile.py +++ b/tests/integration/cli/test_compile.py @@ -24,6 +24,7 @@ "only-dependencies", "test", "bad-contracts", + "script", "with-dependencies", "with-contracts", ) diff --git a/tests/integration/cli/test_run.py b/tests/integration/cli/test_run.py index 5e3485989d..b0faf306b4 100644 --- a/tests/integration/cli/test_run.py +++ b/tests/integration/cli/test_run.py @@ -19,7 +19,12 @@ def test_run(ape_cli, runner, project): # By default, no commands are run assert "Super secret script output" not in result.output - scripts = [s for s in project.scripts_folder.glob("*.py") if not s.name.startswith("error")] + not_part_of_test = ("output_contract_view_methods",) + scripts = [ + s + for s in project.scripts_folder.glob("*.py") + if not s.name.startswith("error") and s.stem not in not_part_of_test + ] for script_file in scripts: result = runner.invoke(ape_cli, ["run", script_file.stem], catch_exceptions=False) assert ( @@ -161,3 +166,24 @@ def test_scripts_module_already_installed(ape_cli, runner, project, mocker): assert result.exit_code == 0, result.output del sys.modules["scripts"] + + +@skip_projects_except("script") +def test_run_recompiles_if_needed(ape_cli, runner, project): + """ + Ensure that when a change is made to a contract, + when we run a script, it re-compiles the script first. + """ + # Ensure we begin compiled. + runner.invoke(ape_cli, ["compile", "--force"]) + + # Make a change to the contract + contract = project.contracts_folder / "contract.json" + method_name = project.TestContractVy.contract_type.view_methods[0].name + new_method_name = f"f__{method_name}__" + new_contract_text = contract.read_text().replace(method_name, new_method_name) + contract.write_text(new_contract_text) + + # Run the script. It better recompile first! + result = runner.invoke(ape_cli, ["run", "output_contract_view_methods"]) + assert new_method_name in result.output