diff --git a/ens/contract_data.py b/ens/contract_data.py index 53ff9f6443..596393a389 100644 --- a/ens/contract_data.py +++ b/ens/contract_data.py @@ -21,19 +21,19 @@ reverse_resolver_bytecode_runtime = '608060405234801561001057600080fd5b506004361061004c5760003560e01c806301ffc9a7146100515780633e9ce794146100815780639061b9231461009d578063f86bc879146100cd575b600080fd5b61006b6004803603810190610066919061051e565b6100fd565b6040516100789190610566565b60405180910390f35b61009b60048036038101906100969190610641565b61015e565b005b6100b760048036038101906100b291906106f9565b610245565b6040516100c49190610813565b60405180910390f35b6100e760048036038101906100e29190610835565b61042f565b6040516100f49190610566565b60405180910390f35b6000639061b92360e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916148061015757506101568261046b565b5b9050919050565b806001600085815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055507fe1c5610a6e0cbe10764ecd182adcef1ec338dc4e199c99c32ce98f38e12791df8333848460405161023894939291906108a6565b60405180910390a1505050565b60606040518060400160405280601781526020017f11657874656e6465642d7265736f6c766572036574680000000000000000000081525080519060200120858560405161029492919061092a565b60405180910390201480156102ad575060248383905010155b15610328577ff0a378cc2afe91730d0105e67d6bb037cc5b8b6bfec5b5962d9b637ff6497e5560001b83836004906024926102ea9392919061094d565b906102f591906109a0565b146102ff57600080fd5b61beef60405160200161031291906109ff565b6040516020818303038152906040529050610427565b60008585600081811061033e5761033d610a1a565b5b9050013560f81c60f81b60f81c60ff1690506040518060400160405280601781526020017f11657874656e6465642d7265736f6c766572036574680000000000000000000081525080519060200120868683600161039c9190610a82565b9080926103ab9392919061094d565b6040516103b9929190610ad8565b604051809103902014610401576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f890610b28565b60405180910390fd5b61dead60405160200161041491906109ff565b6040516020818303038152906040529150505b949350505050565b6001602052826000526040600020602052816000526040600020602052806000526040600020600092509250509054906101000a900460ff1681565b60006301ffc9a760e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b600080fd5b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b6104fb816104c6565b811461050657600080fd5b50565b600081359050610518816104f2565b92915050565b600060208284031215610534576105336104bc565b5b600061054284828501610509565b91505092915050565b60008115159050919050565b6105608161054b565b82525050565b600060208201905061057b6000830184610557565b92915050565b6000819050919050565b61059481610581565b811461059f57600080fd5b50565b6000813590506105b18161058b565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006105e2826105b7565b9050919050565b6105f2816105d7565b81146105fd57600080fd5b50565b60008135905061060f816105e9565b92915050565b61061e8161054b565b811461062957600080fd5b50565b60008135905061063b81610615565b92915050565b60008060006060848603121561065a576106596104bc565b5b6000610668868287016105a2565b935050602061067986828701610600565b925050604061068a8682870161062c565b9150509250925092565b600080fd5b600080fd5b600080fd5b60008083601f8401126106b9576106b8610694565b5b8235905067ffffffffffffffff8111156106d6576106d5610699565b5b6020830191508360018202830111156106f2576106f161069e565b5b9250929050565b60008060008060408587031215610713576107126104bc565b5b600085013567ffffffffffffffff811115610731576107306104c1565b5b61073d878288016106a3565b9450945050602085013567ffffffffffffffff8111156107605761075f6104c1565b5b61076c878288016106a3565b925092505092959194509250565b600081519050919050565b600082825260208201905092915050565b60005b838110156107b4578082015181840152602081019050610799565b838111156107c3576000848401525b50505050565b6000601f19601f8301169050919050565b60006107e58261077a565b6107ef8185610785565b93506107ff818560208601610796565b610808816107c9565b840191505092915050565b6000602082019050818103600083015261082d81846107da565b905092915050565b60008060006060848603121561084e5761084d6104bc565b5b600061085c868287016105a2565b935050602061086d86828701610600565b925050604061087e86828701610600565b9150509250925092565b61089181610581565b82525050565b6108a0816105d7565b82525050565b60006080820190506108bb6000830187610888565b6108c86020830186610897565b6108d56040830185610897565b6108e26060830184610557565b95945050505050565b600081905092915050565b82818337600083830152505050565b600061091183856108eb565b935061091e8385846108f6565b82840190509392505050565b6000610937828486610905565b91508190509392505050565b600080fd5b600080fd5b6000808585111561096157610960610943565b5b8386111561097257610971610948565b5b6001850283019150848603905094509492505050565b600082905092915050565b600082821b905092915050565b60006109ac8383610988565b826109b78135610581565b925060208210156109f7576109f27fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83602003600802610993565b831692505b505092915050565b6000602082019050610a146000830184610897565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610a8d82610a49565b9150610a9883610a49565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115610acd57610acc610a53565b5b828201905092915050565b6000610ae5828486610905565b91508190509392505050565b600082825260208201905092915050565b50565b6000610b12600083610af1565b9150610b1d82610b02565b600082019050919050565b60006020820190508181036000830152610b4181610b05565b905091905056fea264697066735822122053f3072486d953b17f72555d93bae38d3607f573e572c03ca3b10c082471640064736f6c634300080d0033' # ENSIP-10 - Extended Resolver for Wildcard Resolution -# compiled from `tests/test_contracts/ExtendedResolver.sol` +# compiled from `web3/_utils/contract_sources/ExtendedResolver.sol` extended_resolver_abi = '[{"inputs": [{"internalType": "contract ENS","name": "_ens","type": "address"}],"stateMutability": "nonpayable","type": "constructor"},{"anonymous": false,"inputs": [{"indexed": false,"internalType": "bytes32","name": "node","type": "bytes32"},{"indexed": false,"internalType": "address","name": "owner","type": "address"},{"indexed": false,"internalType": "address","name": "target","type": "address"},{"indexed": false,"internalType": "bool","name": "isAuthorised","type": "bool"}],"name": "AuthorisationChanged","type": "event"},{"inputs": [{"internalType": "bytes32", "name": "", "type": "bytes32"},{"internalType": "address", "name": "", "type": "address"},{"internalType": "address", "name": "", "type": "address"}],"name": "authorisations","outputs": [{"internalType": "bool", "name": "", "type": "bool"}],"stateMutability": "view","type": "function"},{"inputs": [{"internalType": "bytes", "name": "dnsName", "type": "bytes"},{"internalType": "bytes", "name": "data", "type": "bytes"}],"name": "resolve","outputs": [{"internalType": "bytes", "name": "", "type": "bytes"}],"stateMutability": "view","type": "function"},{"inputs": [{"internalType": "bytes32", "name": "node", "type": "bytes32"},{"internalType": "address", "name": "target", "type": "address"},{"internalType": "bool", "name": "isAuthorised", "type": "bool"}],"name": "setAuthorisation","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "bytes4","name": "interfaceID","type": "bytes4"}],"name": "supportsInterface","outputs": [{"internalType": "bool", "name": "", "type": "bool"}],"stateMutability": "pure","type": "function"}]' extended_resolver_bytecode = '608060405234801561001057600080fd5b50604051610dbb380380610dbb833981810160405281019061003291906100ed565b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505061011a565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006100a88261007d565b9050919050565b60006100ba8261009d565b9050919050565b6100ca816100af565b81146100d557600080fd5b50565b6000815190506100e7816100c1565b92915050565b60006020828403121561010357610102610078565b5b6000610111848285016100d8565b91505092915050565b610c92806101296000396000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c806301ffc9a7146100515780633e9ce794146100815780639061b9231461009d578063f86bc879146100cd575b600080fd5b61006b60048036038101906100669190610554565b6100fd565b604051610078919061059c565b60405180910390f35b61009b60048036038101906100969190610677565b61015e565b005b6100b760048036038101906100b2919061072f565b610245565b6040516100c49190610849565b60405180910390f35b6100e760048036038101906100e2919061086b565b610465565b6040516100f4919061059c565b60405180910390f35b6000639061b92360e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614806101575750610156826104a1565b5b9050919050565b806001600085815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055507fe1c5610a6e0cbe10764ecd182adcef1ec338dc4e199c99c32ce98f38e12791df8333848460405161023894939291906108dc565b60405180910390a1505050565b60606040518060400160405280601781526020017f11657874656e6465642d7265736f6c7665720365746800000000000000000000815250805190602001208585604051610294929190610960565b60405180910390201480156102ad575060248383905010155b1561035e577ff0a378cc2afe91730d0105e67d6bb037cc5b8b6bfec5b5962d9b637ff6497e5560001b83836004906024926102ea93929190610983565b906102f591906109d6565b14610335576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161032c90610ab8565b60405180910390fd5b61beef6040516020016103489190610ad8565b604051602081830303815290604052905061045d565b60008585600081811061037457610373610af3565b5b9050013560f81c60f81b60f81c60ff1690506040518060400160405280601781526020017f11657874656e6465642d7265736f6c76657203657468000000000000000000008152508051906020012086868360016103d29190610b5b565b9080926103e193929190610983565b6040516103ef929190610bb1565b604051809103902014610437576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161042e90610c3c565b60405180910390fd5b61dead60405160200161044a9190610ad8565b6040516020818303038152906040529150505b949350505050565b6001602052826000526040600020602052816000526040600020602052806000526040600020600092509250509054906101000a900460ff1681565b60006301ffc9a760e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b600080fd5b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b610531816104fc565b811461053c57600080fd5b50565b60008135905061054e81610528565b92915050565b60006020828403121561056a576105696104f2565b5b60006105788482850161053f565b91505092915050565b60008115159050919050565b61059681610581565b82525050565b60006020820190506105b1600083018461058d565b92915050565b6000819050919050565b6105ca816105b7565b81146105d557600080fd5b50565b6000813590506105e7816105c1565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610618826105ed565b9050919050565b6106288161060d565b811461063357600080fd5b50565b6000813590506106458161061f565b92915050565b61065481610581565b811461065f57600080fd5b50565b6000813590506106718161064b565b92915050565b6000806000606084860312156106905761068f6104f2565b5b600061069e868287016105d8565b93505060206106af86828701610636565b92505060406106c086828701610662565b9150509250925092565b600080fd5b600080fd5b600080fd5b60008083601f8401126106ef576106ee6106ca565b5b8235905067ffffffffffffffff81111561070c5761070b6106cf565b5b602083019150836001820283011115610728576107276106d4565b5b9250929050565b60008060008060408587031215610749576107486104f2565b5b600085013567ffffffffffffffff811115610767576107666104f7565b5b610773878288016106d9565b9450945050602085013567ffffffffffffffff811115610796576107956104f7565b5b6107a2878288016106d9565b925092505092959194509250565b600081519050919050565b600082825260208201905092915050565b60005b838110156107ea5780820151818401526020810190506107cf565b838111156107f9576000848401525b50505050565b6000601f19601f8301169050919050565b600061081b826107b0565b61082581856107bb565b93506108358185602086016107cc565b61083e816107ff565b840191505092915050565b600060208201905081810360008301526108638184610810565b905092915050565b600080600060608486031215610884576108836104f2565b5b6000610892868287016105d8565b93505060206108a386828701610636565b92505060406108b486828701610636565b9150509250925092565b6108c7816105b7565b82525050565b6108d68161060d565b82525050565b60006080820190506108f160008301876108be565b6108fe60208301866108cd565b61090b60408301856108cd565b610918606083018461058d565b95945050505050565b600081905092915050565b82818337600083830152505050565b60006109478385610921565b935061095483858461092c565b82840190509392505050565b600061096d82848661093b565b91508190509392505050565b600080fd5b600080fd5b6000808585111561099757610996610979565b5b838611156109a8576109a761097e565b5b6001850283019150848603905094509492505050565b600082905092915050565b600082821b905092915050565b60006109e283836109be565b826109ed81356105b7565b92506020821015610a2d57610a287fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff836020036008026109c9565b831692505b505092915050565b600082825260208201905092915050565b7f706172656e7420646f6d61696e206e6f742076616c696461746564206170707260008201527f6f7072696174656c790000000000000000000000000000000000000000000000602082015250565b6000610aa2602983610a35565b9150610aad82610a46565b604082019050919050565b60006020820190508181036000830152610ad181610a95565b9050919050565b6000602082019050610aed60008301846108cd565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610b6682610b22565b9150610b7183610b22565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115610ba657610ba5610b2c565b5b828201905092915050565b6000610bbe82848661093b565b91508190509392505050565b7f737562646f6d61696e206e6f742076616c69646174656420617070726f70726960008201527f6174656c79000000000000000000000000000000000000000000000000000000602082015250565b6000610c26602583610a35565b9150610c3182610bca565b604082019050919050565b60006020820190508181036000830152610c5581610c19565b905091905056fea26469706673582212209fff87be19ed85e754d5e2791de6ed052e7e653185e1d47fa94515f851becd2f64736f6c634300080d0033' extended_resolver_bytecode_runtime = '608060405234801561001057600080fd5b506004361061004c5760003560e01c806301ffc9a7146100515780633e9ce794146100815780639061b9231461009d578063f86bc879146100cd575b600080fd5b61006b60048036038101906100669190610554565b6100fd565b604051610078919061059c565b60405180910390f35b61009b60048036038101906100969190610677565b61015e565b005b6100b760048036038101906100b2919061072f565b610245565b6040516100c49190610849565b60405180910390f35b6100e760048036038101906100e2919061086b565b610465565b6040516100f4919061059c565b60405180910390f35b6000639061b92360e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614806101575750610156826104a1565b5b9050919050565b806001600085815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055507fe1c5610a6e0cbe10764ecd182adcef1ec338dc4e199c99c32ce98f38e12791df8333848460405161023894939291906108dc565b60405180910390a1505050565b60606040518060400160405280601781526020017f11657874656e6465642d7265736f6c7665720365746800000000000000000000815250805190602001208585604051610294929190610960565b60405180910390201480156102ad575060248383905010155b1561035e577ff0a378cc2afe91730d0105e67d6bb037cc5b8b6bfec5b5962d9b637ff6497e5560001b83836004906024926102ea93929190610983565b906102f591906109d6565b14610335576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161032c90610ab8565b60405180910390fd5b61beef6040516020016103489190610ad8565b604051602081830303815290604052905061045d565b60008585600081811061037457610373610af3565b5b9050013560f81c60f81b60f81c60ff1690506040518060400160405280601781526020017f11657874656e6465642d7265736f6c76657203657468000000000000000000008152508051906020012086868360016103d29190610b5b565b9080926103e193929190610983565b6040516103ef929190610bb1565b604051809103902014610437576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161042e90610c3c565b60405180910390fd5b61dead60405160200161044a9190610ad8565b6040516020818303038152906040529150505b949350505050565b6001602052826000526040600020602052816000526040600020602052806000526040600020600092509250509054906101000a900460ff1681565b60006301ffc9a760e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b600080fd5b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b610531816104fc565b811461053c57600080fd5b50565b60008135905061054e81610528565b92915050565b60006020828403121561056a576105696104f2565b5b60006105788482850161053f565b91505092915050565b60008115159050919050565b61059681610581565b82525050565b60006020820190506105b1600083018461058d565b92915050565b6000819050919050565b6105ca816105b7565b81146105d557600080fd5b50565b6000813590506105e7816105c1565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610618826105ed565b9050919050565b6106288161060d565b811461063357600080fd5b50565b6000813590506106458161061f565b92915050565b61065481610581565b811461065f57600080fd5b50565b6000813590506106718161064b565b92915050565b6000806000606084860312156106905761068f6104f2565b5b600061069e868287016105d8565b93505060206106af86828701610636565b92505060406106c086828701610662565b9150509250925092565b600080fd5b600080fd5b600080fd5b60008083601f8401126106ef576106ee6106ca565b5b8235905067ffffffffffffffff81111561070c5761070b6106cf565b5b602083019150836001820283011115610728576107276106d4565b5b9250929050565b60008060008060408587031215610749576107486104f2565b5b600085013567ffffffffffffffff811115610767576107666104f7565b5b610773878288016106d9565b9450945050602085013567ffffffffffffffff811115610796576107956104f7565b5b6107a2878288016106d9565b925092505092959194509250565b600081519050919050565b600082825260208201905092915050565b60005b838110156107ea5780820151818401526020810190506107cf565b838111156107f9576000848401525b50505050565b6000601f19601f8301169050919050565b600061081b826107b0565b61082581856107bb565b93506108358185602086016107cc565b61083e816107ff565b840191505092915050565b600060208201905081810360008301526108638184610810565b905092915050565b600080600060608486031215610884576108836104f2565b5b6000610892868287016105d8565b93505060206108a386828701610636565b92505060406108b486828701610636565b9150509250925092565b6108c7816105b7565b82525050565b6108d68161060d565b82525050565b60006080820190506108f160008301876108be565b6108fe60208301866108cd565b61090b60408301856108cd565b610918606083018461058d565b95945050505050565b600081905092915050565b82818337600083830152505050565b60006109478385610921565b935061095483858461092c565b82840190509392505050565b600061096d82848661093b565b91508190509392505050565b600080fd5b600080fd5b6000808585111561099757610996610979565b5b838611156109a8576109a761097e565b5b6001850283019150848603905094509492505050565b600082905092915050565b600082821b905092915050565b60006109e283836109be565b826109ed81356105b7565b92506020821015610a2d57610a287fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff836020036008026109c9565b831692505b505092915050565b600082825260208201905092915050565b7f706172656e7420646f6d61696e206e6f742076616c696461746564206170707260008201527f6f7072696174656c790000000000000000000000000000000000000000000000602082015250565b6000610aa2602983610a35565b9150610aad82610a46565b604082019050919050565b60006020820190508181036000830152610ad181610a95565b9050919050565b6000602082019050610aed60008301846108cd565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610b6682610b22565b9150610b7183610b22565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115610ba657610ba5610b2c565b5b828201905092915050565b6000610bbe82848661093b565b91508190509392505050565b7f737562646f6d61696e206e6f742076616c69646174656420617070726f70726960008201527f6174656c79000000000000000000000000000000000000000000000000000000602082015250565b6000610c26602583610a35565b9150610c3182610bca565b604082019050919050565b60006020820190508181036000830152610c5581610c19565b905091905056fea26469706673582212209fff87be19ed85e754d5e2791de6ed052e7e653185e1d47fa94515f851becd2f64736f6c634300080d0033' # Simple resolver with no support for interfaces like getText(), etc -# compiled from `tests/test_contracts/SimpleResolver.sol` +# compiled from `web3/_utils/contract_sources/SimpleResolver.sol` simple_resolver_abi = json.loads('[{"inputs":[{"internalType":"bytes32","name":"nodeID","type":"bytes32"}],"name":"addr","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]') simple_resolver_bytecode = '608060405234801561001057600080fd5b5061028c806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806301ffc9a71461003b5780633b3b57de1461006b575b600080fd5b61005560048036038101906100509190610134565b61009b565b604051610062919061017c565b60405180910390f35b610085600480360381019061008091906101cd565b6100cd565b604051610092919061023b565b60405180910390f35b6000633b3b57de60e01b827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b6000309050919050565b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b610111816100dc565b811461011c57600080fd5b50565b60008135905061012e81610108565b92915050565b60006020828403121561014a576101496100d7565b5b60006101588482850161011f565b91505092915050565b60008115159050919050565b61017681610161565b82525050565b6000602082019050610191600083018461016d565b92915050565b6000819050919050565b6101aa81610197565b81146101b557600080fd5b50565b6000813590506101c7816101a1565b92915050565b6000602082840312156101e3576101e26100d7565b5b60006101f1848285016101b8565b91505092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610225826101fa565b9050919050565b6102358161021a565b82525050565b6000602082019050610250600083018461022c565b9291505056fea2646970667358221220e9d34e70193fa6e99d9be00bd7b1e4b63dc6fd9c84934a35350d8b2c4215974964736f6c634300080d0033' simple_resolver_bytecode_runtime = '608060405234801561001057600080fd5b50600436106100365760003560e01c806301ffc9a71461003b5780633b3b57de1461006b575b600080fd5b61005560048036038101906100509190610134565b61009b565b604051610062919061017c565b60405180910390f35b610085600480360381019061008091906101cd565b6100cd565b604051610092919061023b565b60405180910390f35b6000633b3b57de60e01b827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b6000309050919050565b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b610111816100dc565b811461011c57600080fd5b50565b60008135905061012e81610108565b92915050565b60006020828403121561014a576101496100d7565b5b60006101588482850161011f565b91505092915050565b60008115159050919050565b61017681610161565b82525050565b6000602082019050610191600083018461016d565b92915050565b6000819050919050565b6101aa81610197565b81146101b557600080fd5b50565b6000813590506101c7816101a1565b92915050565b6000602082840312156101e3576101e26100d7565b5b60006101f1848285016101b8565b91505092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610225826101fa565b9050919050565b6102358161021a565b82525050565b6000602082019050610250600083018461022c565b9291505056fea2646970667358221220e9d34e70193fa6e99d9be00bd7b1e4b63dc6fd9c84934a35350d8b2c4215974964736f6c634300080d0033' # Offchain Resolver for offchain resolution w/ CCIP Read as described in EIP-3668 -# compiled from `tests/test_contracts/OffchainResolver.sol` +# compiled from `web3/_utils/contract_sources/OffchainResolver.sol` offchain_resolver_abi = json.loads('[{"inputs":[{"internalType":"string[]","name":"_urls","type":"string[]"},{"internalType":"address[]","name":"_signers","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"string[]","name":"urls","type":"string[]"},{"internalType":"bytes","name":"callData","type":"bytes"},{"internalType":"bytes4","name":"callbackFunction","type":"bytes4"},{"internalType":"bytes","name":"extraData","type":"bytes"}],"name":"OffchainLookup","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address[]","name":"signers","type":"address[]"}],"name":"NewSigners","type":"event"},{"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"uint64","name":"expires","type":"uint64"},{"internalType":"bytes","name":"request","type":"bytes"},{"internalType":"bytes","name":"result","type":"bytes"}],"name":"makeSignatureHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"name","type":"bytes"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"resolve","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"response","type":"bytes"},{"internalType":"bytes","name":"extraData","type":"bytes"}],"name":"resolveWithProof","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"signers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"url","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]') offchain_resolver_bytecode = "60806040523480156200001157600080fd5b506040516200219038038062002190833981810160405281019062000037919062000511565b81600090805190602001906200004f929190620001a4565b5060005b81518110156200010b5760018060008484815181106200009c577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080620001029062000813565b91505062000053565b5060018060003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055507fab0b9cc3a46b568cb08d985497cde8ab7e18892d01f58db7dc7f0d2af859b2d78160405162000194919062000619565b60405180910390a1505062000919565b828054828255906000526020600020908101928215620001f8579160200282015b82811115620001f7578251829080519060200190620001e69291906200020b565b5091602001919060010190620001c5565b5b5090506200020791906200029c565b5090565b8280546200021990620007a7565b90600052602060002090601f0160209004810192826200023d576000855562000289565b82601f106200025857805160ff191683800117855562000289565b8280016001018555821562000289579182015b82811115620002885782518255916020019190600101906200026b565b5b509050620002989190620002c4565b5090565b5b80821115620002c05760008181620002b69190620002e3565b506001016200029d565b5090565b5b80821115620002df576000816000905550600101620002c5565b5090565b508054620002f190620007a7565b6000825580601f1062000305575062000326565b601f016020900490600052602060002090810190620003259190620002c4565b5b50565b6000620003406200033a8462000666565b6200063d565b905080838252602082019050828560208602820111156200036057600080fd5b60005b8581101562000394578162000379888262000473565b84526020840193506020830192505060018101905062000363565b5050509392505050565b6000620003b5620003af8462000695565b6200063d565b90508083825260208201905082856020860282011115620003d557600080fd5b60005b858110156200042457815167ffffffffffffffff811115620003f957600080fd5b808601620004088982620004e4565b85526020850194506020840193505050600181019050620003d8565b5050509392505050565b6000620004456200043f84620006c4565b6200063d565b9050828152602081018484840111156200045e57600080fd5b6200046b84828562000771565b509392505050565b6000815190506200048481620008ff565b92915050565b600082601f8301126200049c57600080fd5b8151620004ae84826020860162000329565b91505092915050565b600082601f830112620004c957600080fd5b8151620004db8482602086016200039e565b91505092915050565b600082601f830112620004f657600080fd5b8151620005088482602086016200042e565b91505092915050565b600080604083850312156200052557600080fd5b600083015167ffffffffffffffff8111156200054057600080fd5b6200054e85828601620004b7565b925050602083015167ffffffffffffffff8111156200056c57600080fd5b6200057a858286016200048a565b9150509250929050565b60006200059283836200059e565b60208301905092915050565b620005a98162000733565b82525050565b6000620005bc826200070a565b620005c8818562000722565b9350620005d583620006fa565b8060005b838110156200060c578151620005f0888262000584565b9750620005fd8362000715565b925050600181019050620005d9565b5085935050505092915050565b60006020820190508181036000830152620006358184620005af565b905092915050565b6000620006496200065c565b9050620006578282620007dd565b919050565b6000604051905090565b600067ffffffffffffffff821115620006845762000683620008bf565b5b602082029050602081019050919050565b600067ffffffffffffffff821115620006b357620006b2620008bf565b5b602082029050602081019050919050565b600067ffffffffffffffff821115620006e257620006e1620008bf565b5b620006ed82620008ee565b9050602081019050919050565b6000819050602082019050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b6000620007408262000747565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b838110156200079157808201518184015260208101905062000774565b83811115620007a1576000848401525b50505050565b60006002820490506001821680620007c057607f821691505b60208210811415620007d757620007d662000890565b5b50919050565b620007e882620008ee565b810181811067ffffffffffffffff821117156200080a5762000809620008bf565b5b80604052505050565b6000620008208262000767565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141562000856576200085562000861565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b6200090a8162000733565b81146200091657600080fd5b50565b61186780620009296000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c806301ffc9a7146100675780631dcfea0914610097578063736c0d5b146100c7578063796676be146100f75780639061b92314610127578063f4d4d2f814610157575b600080fd5b610081600480360381019061007c9190610cb9565b610187565b60405161008e91906111c9565b60405180910390f35b6100b160048036038101906100ac9190610c26565b610201565b6040516100be91906111e4565b60405180910390f35b6100e160048036038101906100dc9190610bfd565b610219565b6040516100ee91906111c9565b60405180910390f35b610111600480360381019061010c9190610dd6565b610239565b60405161011e91906112a1565b60405180910390f35b610141600480360381019061013c9190610ce2565b6102e5565b60405161014e919061127f565b60405180910390f35b610171600480360381019061016c9190610ce2565b6103b4565b60405161017e919061127f565b60405180910390f35b60007f9061b923000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614806101fa57506101f982610462565b5b9050919050565b600061020f858585856104cc565b9050949350505050565b60016020528060005260406000206000915054906101000a900460ff1681565b6000818154811061024957600080fd5b90600052602060002001600091509050805461026490611541565b80601f016020809104026020016040519081016040528092919081815260200182805461029090611541565b80156102dd5780601f106102b2576101008083540402835291602001916102dd565b820191906000526020600020905b8154815290600101906020018083116102c057829003601f168201915b505050505081565b60606000639061b92360e01b868686866040516024016103089493929190611244565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505090503060008263f4d4d2f860e01b846040517f556f18300000000000000000000000000000000000000000000000000000000081526004016103ab959493929190611161565b60405180910390fd5b60606000806103c585858989610513565b91509150600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610455576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161044c90611323565b60405180910390fd5b8092505050949350505050565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b60008484848051906020012084805190602001206040516020016104f39493929190611108565b604051602081830303815290604052805190602001209050949350505050565b600060606000806000868681019061052b9190610d57565b925092509250600061058c61058630858d8d8080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050886104cc565b836105a1565b90508084955095505050505094509492505050565b60008060006105b085856105c8565b915091506105bd8161064b565b819250505092915050565b60008060418351141561060a5760008060006020860151925060408601519150606086015160001a90506105fe8782858561099c565b94509450505050610644565b60408351141561063b576000806020850151915060408501519050610630868383610aa9565b935093505050610644565b60006002915091505b9250929050565b60006004811115610685577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b8160048111156106be577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b14156106c957610999565b60016004811115610703577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b81600481111561073c577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b141561077d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610774906112c3565b60405180910390fd5b600260048111156107b7577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b8160048111156107f0577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b1415610831576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610828906112e3565b60405180910390fd5b6003600481111561086b577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b8160048111156108a4577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b14156108e5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108dc90611303565b60405180910390fd5b60048081111561091e577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b816004811115610957577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b1415610998576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161098f90611343565b60405180910390fd5b5b50565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08360001c11156109d7576000600391509150610aa0565b601b8560ff16141580156109ef5750601c8560ff1614155b15610a01576000600491509150610aa0565b600060018787878760405160008152602001604052604051610a2694939291906111ff565b6020604051602081039080840390855afa158015610a48573d6000803e3d6000fd5b505050602060405103519050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610a9757600060019250925050610aa0565b80600092509250505b94509492505050565b6000806000807f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85169150601b8560ff1c019050610ae98782888561099c565b935093505050935093915050565b6000610b0a610b0584611388565b611363565b905082815260208101848484011115610b2257600080fd5b610b2d8482856114ff565b509392505050565b600081359050610b44816117d5565b92915050565b600081359050610b59816117ec565b92915050565b60008083601f840112610b7157600080fd5b8235905067ffffffffffffffff811115610b8a57600080fd5b602083019150836001820283011115610ba257600080fd5b9250929050565b600082601f830112610bba57600080fd5b8135610bca848260208601610af7565b91505092915050565b600081359050610be281611803565b92915050565b600081359050610bf78161181a565b92915050565b600060208284031215610c0f57600080fd5b6000610c1d84828501610b35565b91505092915050565b60008060008060808587031215610c3c57600080fd5b6000610c4a87828801610b35565b9450506020610c5b87828801610be8565b935050604085013567ffffffffffffffff811115610c7857600080fd5b610c8487828801610ba9565b925050606085013567ffffffffffffffff811115610ca157600080fd5b610cad87828801610ba9565b91505092959194509250565b600060208284031215610ccb57600080fd5b6000610cd984828501610b4a565b91505092915050565b60008060008060408587031215610cf857600080fd5b600085013567ffffffffffffffff811115610d1257600080fd5b610d1e87828801610b5f565b9450945050602085013567ffffffffffffffff811115610d3d57600080fd5b610d4987828801610b5f565b925092505092959194509250565b600080600060608486031215610d6c57600080fd5b600084013567ffffffffffffffff811115610d8657600080fd5b610d9286828701610ba9565b9350506020610da386828701610be8565b925050604084013567ffffffffffffffff811115610dc057600080fd5b610dcc86828701610ba9565b9150509250925092565b600060208284031215610de857600080fd5b6000610df684828501610bd3565b91505092915050565b6000610e0b8383610f90565b905092915050565b610e1c81611460565b82525050565b610e33610e2e82611460565b6115a4565b82525050565b6000610e44826113e3565b610e4e8185611411565b935083602082028501610e60856113b9565b8060005b85811015610e9b57848403895281610e7c8582610dff565b9450610e8783611404565b925060208a01995050600181019050610e64565b50829750879550505050505092915050565b610eb681611472565b82525050565b610ec58161147e565b82525050565b610edc610ed78261147e565b6115b6565b82525050565b610eeb81611488565b82525050565b6000610efd8385611422565b9350610f0a8385846114ff565b610f1383611642565b840190509392505050565b6000610f29826113ee565b610f338185611422565b9350610f4381856020860161150e565b610f4c81611642565b840191505092915050565b6000610f62826113f9565b610f6c8185611444565b9350610f7c81856020860161150e565b610f8581611642565b840191505092915050565b60008154610f9d81611541565b610fa78186611433565b94506001821660008114610fc25760018114610fd457611007565b60ff1983168652602086019350611007565b610fdd856113ce565b60005b83811015610fff57815481890152600182019150602081019050610fe0565b808801955050505b50505092915050565b600061101d601883611444565b91506110288261166d565b602082019050919050565b6000611040601f83611444565b915061104b82611696565b602082019050919050565b6000611063602283611444565b915061106e826116bf565b604082019050919050565b6000611086602483611444565b91506110918261170e565b604082019050919050565b60006110a9600283611455565b91506110b48261175d565b600282019050919050565b60006110cc602283611444565b91506110d782611786565b604082019050919050565b6110f36110ee826114de565b6115d2565b82525050565b611102816114f2565b82525050565b60006111138261109c565b915061111f8287610e22565b60148201915061112f82866110e2565b60088201915061113f8285610ecb565b60208201915061114f8284610ecb565b60208201915081905095945050505050565b600060a0820190506111766000830188610e13565b81810360208301526111888187610e39565b9050818103604083015261119c8186610f1e565b90506111ab6060830185610ee2565b81810360808301526111bd8184610f1e565b90509695505050505050565b60006020820190506111de6000830184610ead565b92915050565b60006020820190506111f96000830184610ebc565b92915050565b60006080820190506112146000830187610ebc565b61122160208301866110f9565b61122e6040830185610ebc565b61123b6060830184610ebc565b95945050505050565b6000604082019050818103600083015261125f818688610ef1565b90508181036020830152611274818486610ef1565b905095945050505050565b600060208201905081810360008301526112998184610f1e565b905092915050565b600060208201905081810360008301526112bb8184610f57565b905092915050565b600060208201905081810360008301526112dc81611010565b9050919050565b600060208201905081810360008301526112fc81611033565b9050919050565b6000602082019050818103600083015261131c81611056565b9050919050565b6000602082019050818103600083015261133c81611079565b9050919050565b6000602082019050818103600083015261135c816110bf565b9050919050565b600061136d61137e565b90506113798282611573565b919050565b6000604051905090565b600067ffffffffffffffff8211156113a3576113a2611613565b5b6113ac82611642565b9050602081019050919050565b60008190508160005260206000209050919050565b60008190508160005260206000209050919050565b600081549050919050565b600081519050919050565b600081519050919050565b6000600182019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b600082825260208201905092915050565b600082825260208201905092915050565b600081905092915050565b600061146b826114b4565b9050919050565b60008115159050919050565b6000819050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600067ffffffffffffffff82169050919050565b600060ff82169050919050565b82818337600083830152505050565b60005b8381101561152c578082015181840152602081019050611511565b8381111561153b576000848401525b50505050565b6000600282049050600182168061155957607f821691505b6020821081141561156d5761156c6115e4565b5b50919050565b61157c82611642565b810181811067ffffffffffffffff8211171561159b5761159a611613565b5b80604052505050565b60006115af826115c0565b9050919050565b6000819050919050565b60006115cb82611660565b9050919050565b60006115dd82611653565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b60008160c01b9050919050565b60008160601b9050919050565b7f45434453413a20696e76616c6964207369676e61747572650000000000000000600082015250565b7f45434453413a20696e76616c6964207369676e6174757265206c656e67746800600082015250565b7f45434453413a20696e76616c6964207369676e6174757265202773272076616c60008201527f7565000000000000000000000000000000000000000000000000000000000000602082015250565b7f5369676e617475726556657269666965723a20496e76616c6964207369676e6160008201527f7475726500000000000000000000000000000000000000000000000000000000602082015250565b7f1900000000000000000000000000000000000000000000000000000000000000600082015250565b7f45434453413a20696e76616c6964207369676e6174757265202776272076616c60008201527f7565000000000000000000000000000000000000000000000000000000000000602082015250565b6117de81611460565b81146117e957600080fd5b50565b6117f581611488565b811461180057600080fd5b50565b61180c816114d4565b811461181757600080fd5b50565b611823816114de565b811461182e57600080fd5b5056fea2646970667358221220e5f1e91619d2bc52c11e1bd99d0dabfdbeca91f7eac25e3122f6117fc623900b64736f6c63430008040033" offchain_resolver_bytecode_runtime = "608060405234801561001057600080fd5b50600436106100625760003560e01c806301ffc9a7146100675780631dcfea0914610097578063736c0d5b146100c7578063796676be146100f75780639061b92314610127578063f4d4d2f814610157575b600080fd5b610081600480360381019061007c9190610cb9565b610187565b60405161008e91906111c9565b60405180910390f35b6100b160048036038101906100ac9190610c26565b610201565b6040516100be91906111e4565b60405180910390f35b6100e160048036038101906100dc9190610bfd565b610219565b6040516100ee91906111c9565b60405180910390f35b610111600480360381019061010c9190610dd6565b610239565b60405161011e91906112a1565b60405180910390f35b610141600480360381019061013c9190610ce2565b6102e5565b60405161014e919061127f565b60405180910390f35b610171600480360381019061016c9190610ce2565b6103b4565b60405161017e919061127f565b60405180910390f35b60007f9061b923000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614806101fa57506101f982610462565b5b9050919050565b600061020f858585856104cc565b9050949350505050565b60016020528060005260406000206000915054906101000a900460ff1681565b6000818154811061024957600080fd5b90600052602060002001600091509050805461026490611541565b80601f016020809104026020016040519081016040528092919081815260200182805461029090611541565b80156102dd5780601f106102b2576101008083540402835291602001916102dd565b820191906000526020600020905b8154815290600101906020018083116102c057829003601f168201915b505050505081565b60606000639061b92360e01b868686866040516024016103089493929190611244565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505090503060008263f4d4d2f860e01b846040517f556f18300000000000000000000000000000000000000000000000000000000081526004016103ab959493929190611161565b60405180910390fd5b60606000806103c585858989610513565b91509150600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610455576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161044c90611323565b60405180910390fd5b8092505050949350505050565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b60008484848051906020012084805190602001206040516020016104f39493929190611108565b604051602081830303815290604052805190602001209050949350505050565b600060606000806000868681019061052b9190610d57565b925092509250600061058c61058630858d8d8080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050886104cc565b836105a1565b90508084955095505050505094509492505050565b60008060006105b085856105c8565b915091506105bd8161064b565b819250505092915050565b60008060418351141561060a5760008060006020860151925060408601519150606086015160001a90506105fe8782858561099c565b94509450505050610644565b60408351141561063b576000806020850151915060408501519050610630868383610aa9565b935093505050610644565b60006002915091505b9250929050565b60006004811115610685577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b8160048111156106be577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b14156106c957610999565b60016004811115610703577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b81600481111561073c577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b141561077d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610774906112c3565b60405180910390fd5b600260048111156107b7577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b8160048111156107f0577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b1415610831576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610828906112e3565b60405180910390fd5b6003600481111561086b577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b8160048111156108a4577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b14156108e5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108dc90611303565b60405180910390fd5b60048081111561091e577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b816004811115610957577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b1415610998576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161098f90611343565b60405180910390fd5b5b50565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08360001c11156109d7576000600391509150610aa0565b601b8560ff16141580156109ef5750601c8560ff1614155b15610a01576000600491509150610aa0565b600060018787878760405160008152602001604052604051610a2694939291906111ff565b6020604051602081039080840390855afa158015610a48573d6000803e3d6000fd5b505050602060405103519050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610a9757600060019250925050610aa0565b80600092509250505b94509492505050565b6000806000807f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85169150601b8560ff1c019050610ae98782888561099c565b935093505050935093915050565b6000610b0a610b0584611388565b611363565b905082815260208101848484011115610b2257600080fd5b610b2d8482856114ff565b509392505050565b600081359050610b44816117d5565b92915050565b600081359050610b59816117ec565b92915050565b60008083601f840112610b7157600080fd5b8235905067ffffffffffffffff811115610b8a57600080fd5b602083019150836001820283011115610ba257600080fd5b9250929050565b600082601f830112610bba57600080fd5b8135610bca848260208601610af7565b91505092915050565b600081359050610be281611803565b92915050565b600081359050610bf78161181a565b92915050565b600060208284031215610c0f57600080fd5b6000610c1d84828501610b35565b91505092915050565b60008060008060808587031215610c3c57600080fd5b6000610c4a87828801610b35565b9450506020610c5b87828801610be8565b935050604085013567ffffffffffffffff811115610c7857600080fd5b610c8487828801610ba9565b925050606085013567ffffffffffffffff811115610ca157600080fd5b610cad87828801610ba9565b91505092959194509250565b600060208284031215610ccb57600080fd5b6000610cd984828501610b4a565b91505092915050565b60008060008060408587031215610cf857600080fd5b600085013567ffffffffffffffff811115610d1257600080fd5b610d1e87828801610b5f565b9450945050602085013567ffffffffffffffff811115610d3d57600080fd5b610d4987828801610b5f565b925092505092959194509250565b600080600060608486031215610d6c57600080fd5b600084013567ffffffffffffffff811115610d8657600080fd5b610d9286828701610ba9565b9350506020610da386828701610be8565b925050604084013567ffffffffffffffff811115610dc057600080fd5b610dcc86828701610ba9565b9150509250925092565b600060208284031215610de857600080fd5b6000610df684828501610bd3565b91505092915050565b6000610e0b8383610f90565b905092915050565b610e1c81611460565b82525050565b610e33610e2e82611460565b6115a4565b82525050565b6000610e44826113e3565b610e4e8185611411565b935083602082028501610e60856113b9565b8060005b85811015610e9b57848403895281610e7c8582610dff565b9450610e8783611404565b925060208a01995050600181019050610e64565b50829750879550505050505092915050565b610eb681611472565b82525050565b610ec58161147e565b82525050565b610edc610ed78261147e565b6115b6565b82525050565b610eeb81611488565b82525050565b6000610efd8385611422565b9350610f0a8385846114ff565b610f1383611642565b840190509392505050565b6000610f29826113ee565b610f338185611422565b9350610f4381856020860161150e565b610f4c81611642565b840191505092915050565b6000610f62826113f9565b610f6c8185611444565b9350610f7c81856020860161150e565b610f8581611642565b840191505092915050565b60008154610f9d81611541565b610fa78186611433565b94506001821660008114610fc25760018114610fd457611007565b60ff1983168652602086019350611007565b610fdd856113ce565b60005b83811015610fff57815481890152600182019150602081019050610fe0565b808801955050505b50505092915050565b600061101d601883611444565b91506110288261166d565b602082019050919050565b6000611040601f83611444565b915061104b82611696565b602082019050919050565b6000611063602283611444565b915061106e826116bf565b604082019050919050565b6000611086602483611444565b91506110918261170e565b604082019050919050565b60006110a9600283611455565b91506110b48261175d565b600282019050919050565b60006110cc602283611444565b91506110d782611786565b604082019050919050565b6110f36110ee826114de565b6115d2565b82525050565b611102816114f2565b82525050565b60006111138261109c565b915061111f8287610e22565b60148201915061112f82866110e2565b60088201915061113f8285610ecb565b60208201915061114f8284610ecb565b60208201915081905095945050505050565b600060a0820190506111766000830188610e13565b81810360208301526111888187610e39565b9050818103604083015261119c8186610f1e565b90506111ab6060830185610ee2565b81810360808301526111bd8184610f1e565b90509695505050505050565b60006020820190506111de6000830184610ead565b92915050565b60006020820190506111f96000830184610ebc565b92915050565b60006080820190506112146000830187610ebc565b61122160208301866110f9565b61122e6040830185610ebc565b61123b6060830184610ebc565b95945050505050565b6000604082019050818103600083015261125f818688610ef1565b90508181036020830152611274818486610ef1565b905095945050505050565b600060208201905081810360008301526112998184610f1e565b905092915050565b600060208201905081810360008301526112bb8184610f57565b905092915050565b600060208201905081810360008301526112dc81611010565b9050919050565b600060208201905081810360008301526112fc81611033565b9050919050565b6000602082019050818103600083015261131c81611056565b9050919050565b6000602082019050818103600083015261133c81611079565b9050919050565b6000602082019050818103600083015261135c816110bf565b9050919050565b600061136d61137e565b90506113798282611573565b919050565b6000604051905090565b600067ffffffffffffffff8211156113a3576113a2611613565b5b6113ac82611642565b9050602081019050919050565b60008190508160005260206000209050919050565b60008190508160005260206000209050919050565b600081549050919050565b600081519050919050565b600081519050919050565b6000600182019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b600082825260208201905092915050565b600082825260208201905092915050565b600081905092915050565b600061146b826114b4565b9050919050565b60008115159050919050565b6000819050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600067ffffffffffffffff82169050919050565b600060ff82169050919050565b82818337600083830152505050565b60005b8381101561152c578082015181840152602081019050611511565b8381111561153b576000848401525b50505050565b6000600282049050600182168061155957607f821691505b6020821081141561156d5761156c6115e4565b5b50919050565b61157c82611642565b810181811067ffffffffffffffff8211171561159b5761159a611613565b5b80604052505050565b60006115af826115c0565b9050919050565b6000819050919050565b60006115cb82611660565b9050919050565b60006115dd82611653565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b60008160c01b9050919050565b60008160601b9050919050565b7f45434453413a20696e76616c6964207369676e61747572650000000000000000600082015250565b7f45434453413a20696e76616c6964207369676e6174757265206c656e67746800600082015250565b7f45434453413a20696e76616c6964207369676e6174757265202773272076616c60008201527f7565000000000000000000000000000000000000000000000000000000000000602082015250565b7f5369676e617475726556657269666965723a20496e76616c6964207369676e6160008201527f7475726500000000000000000000000000000000000000000000000000000000602082015250565b7f1900000000000000000000000000000000000000000000000000000000000000600082015250565b7f45434453413a20696e76616c6964207369676e6174757265202776272076616c60008201527f7565000000000000000000000000000000000000000000000000000000000000602082015250565b6117de81611460565b81146117e957600080fd5b50565b6117f581611488565b811461180057600080fd5b50565b61180c816114d4565b811461181757600080fd5b50565b611823816114de565b811461182e57600080fd5b5056fea2646970667358221220e5f1e91619d2bc52c11e1bd99d0dabfdbeca91f7eac25e3122f6117fc623900b64736f6c63430008040033" diff --git a/tests/core/contracts/test_offchain_lookup.py b/tests/core/contracts/test_offchain_lookup.py new file mode 100644 index 0000000000..1f7c8a0035 --- /dev/null +++ b/tests/core/contracts/test_offchain_lookup.py @@ -0,0 +1,120 @@ +import pytest + +from eth_abi import ( + decode_abi, +) + +from web3._utils.module_testing.offchain_lookup_contract import ( + OFFCHAIN_LOOKUP_ABI, + OFFCHAIN_LOOKUP_BYTECODE, + OFFCHAIN_LOOKUP_BYTECODE_RUNTIME, +) +from web3._utils.module_testing.utils import ( + mock_offchain_lookup_request_response, +) +from web3._utils.type_conversion_utils import ( + to_hex_if_bytes, +) +from web3.exceptions import ( + TooManyRequests, +) + +# "test offchain lookup" as an abi-encoded string +OFFCHAIN_LOOKUP_TEST_DATA = '0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001474657374206f6666636861696e206c6f6f6b7570000000000000000000000000' # noqa: E501 +# "web3py" as an abi-encoded string +WEB3PY_AS_HEXBYTES = '0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000067765623370790000000000000000000000000000000000000000000000000000' # noqa: E501 + + +@pytest.fixture +def OffchainLookup(w3): + # compiled from `web3/_utils/module_testing/contract_sources/OffchainLookup.sol` + return w3.eth.contract( + abi=OFFCHAIN_LOOKUP_ABI, + bytecode=OFFCHAIN_LOOKUP_BYTECODE, + bytecode_runtime=OFFCHAIN_LOOKUP_BYTECODE_RUNTIME, + ) + + +@pytest.fixture +def offchain_lookup_contract( + w3, wait_for_block, OffchainLookup, wait_for_transaction, address_conversion_func, +): + wait_for_block(w3) + deploy_txn_hash = OffchainLookup.constructor().transact({'gas': 10000000}) + deploy_receipt = wait_for_transaction(w3, deploy_txn_hash) + contract_address = address_conversion_func(deploy_receipt['contractAddress']) + + bytecode = w3.eth.get_code(contract_address) + assert bytecode == OffchainLookup.bytecode_runtime + deployed_offchain_lookup = OffchainLookup(address=contract_address) + assert deployed_offchain_lookup.address == contract_address + return deployed_offchain_lookup + + +def test_offchain_lookup_functionality( + offchain_lookup_contract, monkeypatch, +): + normalized_address = to_hex_if_bytes(offchain_lookup_contract.address) + mock_offchain_lookup_request_response( + monkeypatch, + mocked_request_url=f'https://web3.py/gateway/{normalized_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_json_data=WEB3PY_AS_HEXBYTES, + ) + response = offchain_lookup_contract.caller.testOffchainLookup(OFFCHAIN_LOOKUP_TEST_DATA) + assert decode_abi(['string'], response)[0] == 'web3py' + + +@pytest.mark.parametrize('status_code_non_4xx_error', [100, 300, 500, 600]) +def test_eth_call_offchain_lookup_tries_next_url_for_non_4xx_error_status_and_tests_POST( + offchain_lookup_contract, monkeypatch, status_code_non_4xx_error, +) -> None: + normalized_contract_address = to_hex_if_bytes(offchain_lookup_contract.address).lower() + + # The next url in our test contract doesn't contain '{data}', triggering the POST request + # logic. The idea here is to return a bad status for the first url (GET) and a success + # status from the second call (POST) to test both that we move on to the next url with + # non 4xx status and that the POST logic is also working as expected. + mock_offchain_lookup_request_response( + monkeypatch, + mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_status_code=status_code_non_4xx_error, + mocked_json_data=WEB3PY_AS_HEXBYTES, + ) + mock_offchain_lookup_request_response( + monkeypatch, + http_method='POST', + mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}.json', + mocked_status_code=200, + mocked_json_data=WEB3PY_AS_HEXBYTES, + sender=normalized_contract_address, + calldata=OFFCHAIN_LOOKUP_TEST_DATA, + ) + response = offchain_lookup_contract.caller.testOffchainLookup(OFFCHAIN_LOOKUP_TEST_DATA) + assert decode_abi(['string'], response)[0] == 'web3py' + + +@pytest.mark.parametrize('status_code_4xx_error', [400, 410, 450, 499]) +def test_eth_call_offchain_lookup_calls_raise_for_status_for_4xx_status_code( + offchain_lookup_contract, monkeypatch, status_code_4xx_error, +) -> None: + normalized_contract_address = to_hex_if_bytes(offchain_lookup_contract.address).lower() + mock_offchain_lookup_request_response( + monkeypatch, + mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_status_code=status_code_4xx_error, + mocked_json_data=WEB3PY_AS_HEXBYTES, + ) + with pytest.raises(Exception, match="called raise_for_status\\(\\)"): + offchain_lookup_contract.caller.testOffchainLookup(OFFCHAIN_LOOKUP_TEST_DATA) + + +def test_offchain_lookup_raises_on_continuous_redirect( + offchain_lookup_contract, monkeypatch, +): + normalized_address = to_hex_if_bytes(offchain_lookup_contract.address) + mock_offchain_lookup_request_response( + monkeypatch, + mocked_request_url=f'https://web3.py/gateway/{normalized_address}/0x.json', + ) + with pytest.raises(TooManyRequests, match="Too many CCIP read redirects"): + offchain_lookup_contract.caller.continuousOffchainLookup() diff --git a/tests/ens/test_offchain_resolution.py b/tests/ens/test_offchain_resolution.py index 64dcace73f..ef929f55b8 100644 --- a/tests/ens/test_offchain_resolution.py +++ b/tests/ens/test_offchain_resolution.py @@ -46,6 +46,8 @@ class MockHttpSuccessResponse: + status_code = 200 + def __init__(self, request_type, *args, **_kwargs): # validate the expected urls if request_type == 'get': @@ -54,25 +56,23 @@ def __init__(self, request_type, *args, **_kwargs): assert args[1] == EXPECTED_POST_URL @staticmethod - def raise_for_status(): - pass + def raise_for_status(): pass # noqa: E704 @staticmethod - def json(): - return {'data': OFFCHAIN_RESOLVER_DATA} + def json(): return {'data': OFFCHAIN_RESOLVER_DATA} # noqa: E704 class MockHttpBadFormatResponse: + status_code = 200 + def __init__(self, *args): assert args[1] == EXPECTED_GET_URL @staticmethod - def raise_for_status(): - pass + def raise_for_status(): pass # noqa: E704 @staticmethod - def json(): - return {'not_data': OFFCHAIN_RESOLVER_DATA} + def json(): return {'not_data': OFFCHAIN_RESOLVER_DATA} # noqa: E704 def test_offchain_resolution_with_get_request(ens, monkeypatch): diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index c9671aa285..241eec652a 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -9,6 +9,10 @@ MATH_ABI, MATH_BYTECODE, ) +from web3._utils.module_testing.offchain_lookup_contract import ( + OFFCHAIN_LOOKUP_ABI, + OFFCHAIN_LOOKUP_BYTECODE, +) from web3._utils.module_testing.revert_contract import ( _REVERT_CONTRACT_ABI, REVERT_CONTRACT_BYTECODE, @@ -37,6 +41,14 @@ def revert_contract_factory(w3): return contract_factory +@pytest.fixture(scope="module") +def offchain_lookup_contract_factory(w3): + contract_factory = w3.eth.contract( + abi=OFFCHAIN_LOOKUP_ABI, bytecode=OFFCHAIN_LOOKUP_BYTECODE + ) + return contract_factory + + @pytest.fixture(scope="module") def event_loop(request): loop = asyncio.get_event_loop_policy().new_event_loop() diff --git a/tests/integration/generate_fixtures/go_ethereum.py b/tests/integration/generate_fixtures/go_ethereum.py index eadbfb00bc..cbe431c8a9 100644 --- a/tests/integration/generate_fixtures/go_ethereum.py +++ b/tests/integration/generate_fixtures/go_ethereum.py @@ -3,6 +3,7 @@ import os import pprint import shutil +import socket import subprocess import sys import time @@ -21,9 +22,6 @@ ) import common -from tests.utils import ( - get_open_port, -) from web3 import Web3 from web3._utils.module_testing.emitter_contract import ( CONTRACT_EMITTER_ABI, @@ -34,12 +32,24 @@ MATH_ABI, MATH_BYTECODE, ) +from web3._utils.module_testing.offchain_lookup_contract import ( + OFFCHAIN_LOOKUP_ABI, + OFFCHAIN_LOOKUP_BYTECODE, +) from web3._utils.module_testing.revert_contract import ( _REVERT_CONTRACT_ABI, REVERT_CONTRACT_BYTECODE, ) +def get_open_port(): + sock = socket.socket() + sock.bind(('127.0.0.1', 0)) + port = sock.getsockname()[1] + sock.close() + return str(port) + + @contextlib.contextmanager def graceful_kill_on_exit(proc): try: @@ -258,6 +268,18 @@ def setup_chain_state(w3): block_hash_revert_no_msg = w3.eth.get_block(txn_receipt_revert_with_no_msg['blockHash']) print('BLOCK_HASH_REVERT_NO_MSG:', block_hash_revert_no_msg['hash']) + # + # Offchain Lookup Contract + # + offchain_lookup_factory = w3.eth.contract( + abi=OFFCHAIN_LOOKUP_ABI, + bytecode=OFFCHAIN_LOOKUP_BYTECODE, + ) + offchain_lookup_deploy_receipt = common.deploy_contract( + w3, 'offchain_lookup', offchain_lookup_factory + ) + assert is_dict(offchain_lookup_deploy_receipt) + # # Empty Block # @@ -290,6 +312,7 @@ def setup_chain_state(w3): 'math_address': math_deploy_receipt['contractAddress'], 'emitter_deploy_txn_hash': emitter_deploy_receipt['transactionHash'], 'emitter_address': emitter_deploy_receipt['contractAddress'], + 'offchain_lookup_address': offchain_lookup_deploy_receipt['contractAddress'], 'txn_hash_with_log': txn_hash_with_log, 'block_hash_with_log': block_with_log['hash'], 'empty_block_hash': empty_block['hash'], diff --git a/tests/integration/geth-1.10.17-fixture.zip b/tests/integration/geth-1.10.17-fixture.zip index cf4a8ab6df..0cd0e7d5c0 100644 Binary files a/tests/integration/geth-1.10.17-fixture.zip and b/tests/integration/geth-1.10.17-fixture.zip differ diff --git a/tests/integration/go_ethereum/conftest.py b/tests/integration/go_ethereum/conftest.py index c4ce4bf79a..d861e47dd1 100644 --- a/tests/integration/go_ethereum/conftest.py +++ b/tests/integration/go_ethereum/conftest.py @@ -236,3 +236,8 @@ def block_hash_revert_with_msg(geth_fixture_data): @pytest.fixture(scope="module") def revert_contract(revert_contract_factory, geth_fixture_data): return revert_contract_factory(address=geth_fixture_data['revert_address']) + + +@pytest.fixture(scope="module") +def offchain_lookup_contract(offchain_lookup_contract_factory, geth_fixture_data): + return offchain_lookup_contract_factory(address=geth_fixture_data['offchain_lookup_address']) diff --git a/tests/integration/test_ethereum_tester.py b/tests/integration/test_ethereum_tester.py index c688fa1f14..d3390a1bdb 100644 --- a/tests/integration/test_ethereum_tester.py +++ b/tests/integration/test_ethereum_tester.py @@ -159,6 +159,21 @@ def revert_contract(w3, revert_contract_factory, revert_contract_deploy_txn_hash return revert_contract_factory(contract_address) +# +# Offchain Lookup Contract Setup +# +@pytest.fixture(scope="module") +def offchain_lookup_contract(w3, offchain_lookup_contract_factory): + deploy_txn_hash = offchain_lookup_contract_factory.constructor().transact( + {'from': w3.eth.coinbase} + ) + deploy_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn_hash) + assert is_dict(deploy_receipt) + contract_address = deploy_receipt['contractAddress'] + assert is_checksum_address(contract_address) + return offchain_lookup_contract_factory(contract_address) + + UNLOCKABLE_PRIVATE_KEY = '0x392f63a79b1ff8774845f3fa69de4a13800a59e7083f5187f1558f0797ad0f01' diff --git a/tests/core/contracts/contract_sources/Emitter.sol b/web3/_utils/contract_sources/Emitter.sol similarity index 100% rename from tests/core/contracts/contract_sources/Emitter.sol rename to web3/_utils/contract_sources/Emitter.sol diff --git a/tests/core/contracts/contract_sources/Emitter_old.sol b/web3/_utils/contract_sources/Emitter_old.sol similarity index 100% rename from tests/core/contracts/contract_sources/Emitter_old.sol rename to web3/_utils/contract_sources/Emitter_old.sol diff --git a/tests/ens/test_contracts/ExtendedResolver.sol b/web3/_utils/contract_sources/ExtendedResolver.sol similarity index 100% rename from tests/ens/test_contracts/ExtendedResolver.sol rename to web3/_utils/contract_sources/ExtendedResolver.sol diff --git a/web3/_utils/contract_sources/OffchainLookup.sol b/web3/_utils/contract_sources/OffchainLookup.sol new file mode 100644 index 0000000000..3d2a1649d7 --- /dev/null +++ b/web3/_utils/contract_sources/OffchainLookup.sol @@ -0,0 +1,54 @@ +// This contract is meant to test CCIP Read / Offchain Lookup functionality as part of EIP-3668. Multiple functions +// may be added here for testing and the contract can be recompiled for `test_offchain_lookup.py` and other tests. + +pragma solidity ^0.8.13; + +contract OffchainLookupTests { + string[] urls = ["https://web3.py/gateway/{sender}/{data}.json", "https://web3.py/gateway/{sender}.json"]; + + error OffchainLookup(address sender, string[] urls, bytes callData, bytes4 callbackFunction, bytes extraData); + + // This function is meant to test the offchain lookup functionality specified in EIP-3668. + function testOffchainLookup(bytes calldata specifiedDataFromTest) external returns(bytes memory) { + // assert that the test specifies "offchain lookup test" to start the test + string memory dataFromTestAsString = abi.decode(specifiedDataFromTest, (string)); + require(keccak256(abi.encodePacked(dataFromTestAsString)) == keccak256("test offchain lookup"), "test data validation failed."); + + revert OffchainLookup( + address(this), + urls, + specifiedDataFromTest, + this.testOffchainLookupWithProof.selector, + specifiedDataFromTest + ); + } + + function testOffchainLookupWithProof(bytes calldata result, bytes calldata extraData) external returns(bytes memory) { + // assert the result came from the mocked response from our tests... must mock in tests with the appropriate + // value and validate the assertion here. + string memory resultAsString = abi.decode(result, (string)); + require(keccak256(abi.encodePacked(resultAsString)) == keccak256("web3py"), "http request result validation failed."); + + // assert this `extraData` value is the same test-provided value from the original revert at `testOffchainLookup()` + string memory extraDataAsString = abi.decode(extraData, (string)); + require(keccak256(abi.encodePacked(extraDataAsString)) == keccak256("test offchain lookup"), "extraData validation failed."); + + return result; + } + + // This function is meant to test that continuous OffchainLookup reverts raise an exception after too many + // redirects. This example technically breaks the flow described in EIP-3668 but this is solely meant to trigger + // continuous OffchainLookup reverts and test that we catch this sort of activity and stop it. Currently this limit + // is set to 4 redirects. + function continuousOffchainLookup() external returns(bytes memory) { + bytes memory _callData; + + revert OffchainLookup( + address(this), + urls, + _callData, + this.continuousOffchainLookup.selector, + _callData + ); + } +} diff --git a/tests/ens/test_contracts/OffchainResolver.sol b/web3/_utils/contract_sources/OffchainResolver.sol similarity index 96% rename from tests/ens/test_contracts/OffchainResolver.sol rename to web3/_utils/contract_sources/OffchainResolver.sol index 7c2ff39332..863beffdfa 100644 --- a/tests/ens/test_contracts/OffchainResolver.sol +++ b/web3/_utils/contract_sources/OffchainResolver.sol @@ -1,7 +1,9 @@ -// This contract is a much simpler version of the contract set up on mainnet for 'offchainexample.eth', deployed at -// the address 0xC1735677a60884ABbCF72295E88d47764BeDa282. We get rid of the 'expires' time constraint on the -// SignatureVerifier.verify() check so that we can use an actual 'data' payload that comes back from resolving via -// the OffchainResolver for 'offchainexample.eth' on mainnet. A bit hacky but it works for the purpose of testing :) +/** + * This contract is a much simpler version of the contract set up on mainnet for 'offchainexample.eth', deployed at + * the address 0xC1735677a60884ABbCF72295E88d47764BeDa282. We get rid of the 'expires' time constraint on the + * SignatureVerifier.verify() check so that we can use an actual 'data' payload that comes back from resolving via + * the OffchainResolver for 'offchainexample.eth' on mainnet. A bit hacky but it works for the purpose of testing :) + */ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) diff --git a/tests/ens/test_contracts/SimpleResolver.sol b/web3/_utils/contract_sources/SimpleResolver.sol similarity index 100% rename from tests/ens/test_contracts/SimpleResolver.sol rename to web3/_utils/contract_sources/SimpleResolver.sol diff --git a/web3/_utils/module_testing/emitter_contract_old.py b/web3/_utils/module_testing/emitter_contract_old.py index 789699d8eb..1cacae0f36 100644 --- a/web3/_utils/module_testing/emitter_contract_old.py +++ b/web3/_utils/module_testing/emitter_contract_old.py @@ -4,6 +4,8 @@ # compiled with `0.8.11`. # See: https://github.com/ethereum/web3.py/issues/2301 +# contract source at web3/_utils/contract_sources/Emitter_old.sol + CONTRACT_EMITTER_CODE_OLD = ( "608060405234801561001057600080fd5b50610aed806100206000396000f300608060405260043" "6106100ae5763ffffffff7c01000000000000000000000000000000000000000000000000000000" diff --git a/web3/_utils/module_testing/eth_module.py b/web3/_utils/module_testing/eth_module.py index 5f0ec7e88b..8fec309cc5 100644 --- a/web3/_utils/module_testing/eth_module.py +++ b/web3/_utils/module_testing/eth_module.py @@ -1,11 +1,9 @@ import json import math import pytest -import time from typing import ( TYPE_CHECKING, Callable, - Sequence, Union, cast, ) @@ -42,6 +40,15 @@ from web3._utils.method_formatters import ( to_hex_if_integer, ) +from web3._utils.module_testing.utils import ( + assert_contains_log, + mine_pending_block, + mock_async_offchain_lookup_request_response, + mock_offchain_lookup_request_response, +) +from web3._utils.type_conversion_utils import ( + to_hex_if_bytes, +) from web3.exceptions import ( BlockNotFound, ContractLogicError, @@ -49,6 +56,7 @@ InvalidTransaction, NameNotFound, TimeExhausted, + TooManyRequests, TransactionNotFound, TransactionTypeMismatch, ValidationError, @@ -74,37 +82,15 @@ UNKNOWN_ADDRESS = ChecksumAddress(HexAddress(HexStr('0xdEADBEeF00000000000000000000000000000000'))) UNKNOWN_HASH = HexStr('0xdeadbeef00000000000000000000000000000000000000000000000000000000') +# "test offchain lookup" as an abi-encoded string +OFFCHAIN_LOOKUP_TEST_DATA = '0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001474657374206f6666636861696e206c6f6f6b7570000000000000000000000000' # noqa: E501 +# "web3py" as an abi-encoded string +WEB3PY_AS_HEXBYTES = '0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000067765623370790000000000000000000000000000000000000000000000000000' # noqa: E501 if TYPE_CHECKING: from web3 import Web3 # noqa: F401 from web3.contract import Contract # noqa: F401 - - -def mine_pending_block(w3: "Web3") -> None: - timeout = 10 - - w3.geth.miner.start() # type: ignore - start = time.time() - while time.time() < start + timeout: - if len(w3.eth.get_block('pending')['transactions']) == 0: - break - w3.geth.miner.stop() # type: ignore - - -def _assert_contains_log( - result: Sequence[LogReceipt], - block_with_txn_with_log: BlockData, - emitter_contract_address: ChecksumAddress, - txn_hash_with_log: HexStr, -) -> None: - assert len(result) == 1 - log_entry = result[0] - assert log_entry['blockNumber'] == block_with_txn_with_log['number'] - assert log_entry['blockHash'] == block_with_txn_with_log['hash'] - assert log_entry['logIndex'] == 0 - assert is_same_address(log_entry['address'], emitter_contract_address) - assert log_entry['transactionIndex'] == 0 - assert log_entry['transactionHash'] == HexBytes(txn_hash_with_log) + from _pytest.monkeypatch import MonkeyPatch # noqa: F401 class AsyncEthModuleTest: @@ -767,6 +753,132 @@ async def test_eth_call_revert_without_msg( ) await async_w3.eth.call(txn_params) # type: ignore + @pytest.mark.asyncio + async def test_eth_call_offchain_lookup( + self, + async_w3: "Web3", + offchain_lookup_contract: "Contract", + unlocked_account: ChecksumAddress, + monkeypatch: "MonkeyPatch", + ) -> None: + normalized_contract_address = to_hex_if_bytes(offchain_lookup_contract.address).lower() + mock_async_offchain_lookup_request_response( + monkeypatch, + mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_json_data=WEB3PY_AS_HEXBYTES, + ) + # TODO: change to contract call when async Contract is supported + tx = { + 'to': offchain_lookup_contract.address, + 'data': '0x6337ed58000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001474657374206f6666636861696e206c6f6f6b7570000000000000000000000000' # noqa: E501 + } + async_w3.provider.ccip_read_enabled = True + response = await async_w3.eth.call(tx) # type: ignore + response_as_bytes = async_w3.codec.decode_abi(['bytes'], response)[0] + decoded_as_string = async_w3.codec.decode_abi(['string'], response_as_bytes)[0] + assert decoded_as_string == 'web3py' + + @pytest.mark.asyncio + @pytest.mark.parametrize('status_code_non_4xx_error', [100, 300, 500, 600]) + async def test_eth_call_offchain_lookup_tries_next_url_for_non_4xx_error_status_and_tests_POST( + self, + async_w3: "Web3", + offchain_lookup_contract: "Contract", + unlocked_account: ChecksumAddress, + monkeypatch: "MonkeyPatch", + status_code_non_4xx_error: int, + ) -> None: + normalized_contract_address = to_hex_if_bytes(offchain_lookup_contract.address).lower() + + # The next url in our test contract doesn't contain '{data}', triggering the POST request + # logic. The idea here is to return a bad status for the first url (GET) and a success + # status for the second call (POST) to test both that we move on to the next url with + # non-4xx status and that the POST logic is also working as expected. + mock_async_offchain_lookup_request_response( + monkeypatch, + mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_status_code=status_code_non_4xx_error, + mocked_json_data=WEB3PY_AS_HEXBYTES, + ) + mock_async_offchain_lookup_request_response( + monkeypatch, + http_method='POST', + mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}.json', + mocked_status_code=200, + mocked_json_data=WEB3PY_AS_HEXBYTES, + sender=normalized_contract_address, + calldata=OFFCHAIN_LOOKUP_TEST_DATA, + ) + # TODO: change to contract call when async Contract is supported + tx = { + 'to': offchain_lookup_contract.address, + 'data': '0x6337ed58000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001474657374206f6666636861696e206c6f6f6b7570000000000000000000000000' # noqa: E501 + } + async_w3.provider.ccip_read_enabled = True + response = await async_w3.eth.call(tx) # type: ignore + response_as_bytes = async_w3.codec.decode_abi(['bytes'], response)[0] + decoded_as_string = async_w3.codec.decode_abi(['string'], response_as_bytes)[0] + assert decoded_as_string == 'web3py' + + @pytest.mark.asyncio + @pytest.mark.parametrize('status_code_4xx_error', [400, 410, 450, 499]) + async def test_eth_call_offchain_lookup_calls_raise_for_status_for_4xx_status_code( + self, + async_w3: "Web3", + offchain_lookup_contract: "Contract", + unlocked_account: ChecksumAddress, + monkeypatch: "MonkeyPatch", + status_code_4xx_error: int, + ) -> None: + normalized_contract_address = to_hex_if_bytes(offchain_lookup_contract.address).lower() + mock_async_offchain_lookup_request_response( + monkeypatch, + mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_status_code=status_code_4xx_error, + mocked_json_data=WEB3PY_AS_HEXBYTES, + ) + with pytest.raises(Exception, match="called raise_for_status\\(\\)"): + # TODO: change to contract call when async Contract is supported + tx = { + 'to': offchain_lookup_contract.address, + 'data': '0x6337ed58000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001474657374206f6666636861696e206c6f6f6b7570000000000000000000000000' # noqa: E501 + } + async_w3.provider.ccip_read_enabled = True + await async_w3.eth.call(tx) # type: ignore + + @pytest.mark.asyncio + async def test_eth_call_offchain_lookup_raises_when_all_supplied_urls_fail( + self, async_w3: "Web3", offchain_lookup_contract: "Contract", + ) -> None: + # GET and POST requests should fail since responses are not mocked + with pytest.raises(Exception, match="Offchain lookup failed for supplied urls"): + # TODO: change to contract call when async Contract is supported + tx = { + 'to': offchain_lookup_contract.address, + 'data': '0x6337ed58000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001474657374206f6666636861696e206c6f6f6b7570000000000000000000000000' # noqa: E501 + } + async_w3.provider.ccip_read_enabled = True + await async_w3.eth.call(tx) # type: ignore + + @pytest.mark.asyncio + async def test_eth_call_continuous_offchain_lookup_raises_with_too_many_requests( + self, + async_w3: "Web3", + offchain_lookup_contract: "Contract", + unlocked_account: ChecksumAddress, + monkeypatch: "MonkeyPatch", + ) -> None: + normalized_contract_address = to_hex_if_bytes(offchain_lookup_contract.address).lower() + mock_async_offchain_lookup_request_response( + monkeypatch, + mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/0x.json', + ) + with pytest.raises(TooManyRequests, match="Too many CCIP read redirects"): + # TODO: change to contract call when async Contract is supported + tx = {'to': offchain_lookup_contract.address, 'data': '0x09a3c01b'} + async_w3.provider.ccip_read_enabled = True + await async_w3.eth.call(tx) # type: ignore + @pytest.mark.asyncio async def test_async_eth_hashrate( self, @@ -990,7 +1102,7 @@ async def test_async_eth_get_logs_with_logs( "toBlock": block_with_txn_with_log['number'], } result = await async_w3.eth.get_logs(filter_params) # type: ignore - _assert_contains_log( + assert_contains_log( result, block_with_txn_with_log, emitter_contract_address, @@ -1002,7 +1114,7 @@ async def test_async_eth_get_logs_with_logs( "fromBlock": BlockNumber(0), } result = await async_w3.eth.get_logs(filter_params) # type: ignore - _assert_contains_log( + assert_contains_log( result, block_with_txn_with_log, emitter_contract_address, @@ -1017,7 +1129,7 @@ async def test_async_eth_get_logs_with_logs( "address": emitter_contract_address, } result = await async_w3.eth.get_logs(filter_params) # type: ignore - _assert_contains_log( + assert_contains_log( result, block_with_txn_with_log, emitter_contract_address, @@ -1043,7 +1155,7 @@ async def test_async_eth_get_logs_with_logs_topic_args( } result = await async_w3.eth.get_logs(filter_params) # type: ignore - _assert_contains_log( + assert_contains_log( result, block_with_txn_with_log, emitter_contract_address, @@ -1058,7 +1170,7 @@ async def test_async_eth_get_logs_with_logs_topic_args( None], } result = await async_w3.eth.get_logs(filter_params) # type: ignore - _assert_contains_log( + assert_contains_log( result, block_with_txn_with_log, emitter_contract_address, @@ -2577,6 +2689,104 @@ def test_eth_call_revert_without_msg( ) w3.eth.call(txn_params) + def test_eth_call_offchain_lookup( + self, + w3: "Web3", + offchain_lookup_contract: "Contract", + unlocked_account: ChecksumAddress, + monkeypatch: "MonkeyPatch", + ) -> None: + normalized_contract_address = to_hex_if_bytes(offchain_lookup_contract.address).lower() + mock_offchain_lookup_request_response( + monkeypatch, + mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_json_data=WEB3PY_AS_HEXBYTES, + ) + response = offchain_lookup_contract.functions.testOffchainLookup( + OFFCHAIN_LOOKUP_TEST_DATA + ).call(ccip_read_enabled=True) + assert w3.codec.decode_abi(['string'], response)[0] == 'web3py' + + @pytest.mark.parametrize('status_code_non_4xx_error', [100, 300, 500, 600]) + def test_eth_call_offchain_lookup_tries_next_url_for_non_4xx_error_status_and_tests_POST( + self, + w3: "Web3", + offchain_lookup_contract: "Contract", + unlocked_account: ChecksumAddress, + monkeypatch: "MonkeyPatch", + status_code_non_4xx_error: int, + ) -> None: + normalized_contract_address = to_hex_if_bytes(offchain_lookup_contract.address).lower() + + # The next url in our test contract doesn't contain '{data}', triggering the POST request + # logic. The idea here is to return a bad status for the first url (GET) and a success + # status from the second call (POST) to test both that we move on to the next url with + # non 4xx status and that the POST logic is also working as expected. + mock_offchain_lookup_request_response( + monkeypatch, + mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_status_code=status_code_non_4xx_error, + mocked_json_data=WEB3PY_AS_HEXBYTES, + ) + mock_offchain_lookup_request_response( + monkeypatch, + http_method='POST', + mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}.json', + mocked_status_code=200, + mocked_json_data=WEB3PY_AS_HEXBYTES, + sender=normalized_contract_address, + calldata=OFFCHAIN_LOOKUP_TEST_DATA, + ) + response = offchain_lookup_contract.functions.testOffchainLookup( + OFFCHAIN_LOOKUP_TEST_DATA + ).call(ccip_read_enabled=True) + assert w3.codec.decode_abi(['string'], response)[0] == 'web3py' + + @pytest.mark.parametrize('status_code_4xx_error', [400, 410, 450, 499]) + def test_eth_call_offchain_lookup_calls_raise_for_status_for_4xx_status_code( + self, + w3: "Web3", + offchain_lookup_contract: "Contract", + unlocked_account: ChecksumAddress, + monkeypatch: "MonkeyPatch", + status_code_4xx_error: int, + ) -> None: + normalized_contract_address = to_hex_if_bytes(offchain_lookup_contract.address).lower() + mock_offchain_lookup_request_response( + monkeypatch, + mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_status_code=status_code_4xx_error, + mocked_json_data=WEB3PY_AS_HEXBYTES, + ) + with pytest.raises(Exception, match="called raise_for_status\\(\\)"): + offchain_lookup_contract.functions.testOffchainLookup( + OFFCHAIN_LOOKUP_TEST_DATA + ).call(ccip_read_enabled=True) + + def test_eth_call_offchain_lookup_raises_when_all_supplied_urls_fail( + self, w3: "Web3", offchain_lookup_contract: "Contract", + ) -> None: + # GET and POST requests should fail since responses are not mocked + with pytest.raises(Exception, match="Offchain lookup failed for supplied urls"): + offchain_lookup_contract.functions.testOffchainLookup( + OFFCHAIN_LOOKUP_TEST_DATA + ).call(ccip_read_enabled=True) + + def test_eth_call_continuous_offchain_lookup_raises_with_too_many_requests( + self, + w3: "Web3", + offchain_lookup_contract: "Contract", + unlocked_account: ChecksumAddress, + monkeypatch: "MonkeyPatch", + ) -> None: + normalized_contract_address = to_hex_if_bytes(offchain_lookup_contract.address).lower() + mock_offchain_lookup_request_response( + monkeypatch, + mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/0x.json', + ) + with pytest.raises(TooManyRequests, match="Too many CCIP read redirects"): + offchain_lookup_contract.caller(ccip_read_enabled=True).continuousOffchainLookup() + def test_eth_estimate_gas_revert_with_msg( self, w3: "Web3", @@ -3036,7 +3246,7 @@ def test_eth_get_logs_with_logs( "toBlock": block_with_txn_with_log['number'], } result = w3.eth.get_logs(filter_params) - _assert_contains_log( + assert_contains_log( result, block_with_txn_with_log, emitter_contract_address, @@ -3048,7 +3258,7 @@ def test_eth_get_logs_with_logs( "fromBlock": BlockNumber(0), } result = w3.eth.get_logs(filter_params) - _assert_contains_log( + assert_contains_log( result, block_with_txn_with_log, emitter_contract_address, @@ -3081,7 +3291,7 @@ def test_eth_get_logs_with_logs_topic_args( } result = w3.eth.get_logs(filter_params) - _assert_contains_log( + assert_contains_log( result, block_with_txn_with_log, emitter_contract_address, @@ -3096,7 +3306,7 @@ def test_eth_get_logs_with_logs_topic_args( None], } result = w3.eth.get_logs(filter_params) - _assert_contains_log( + assert_contains_log( result, block_with_txn_with_log, emitter_contract_address, diff --git a/web3/_utils/module_testing/offchain_lookup_contract.py b/web3/_utils/module_testing/offchain_lookup_contract.py new file mode 100644 index 0000000000..ee4240b8bd --- /dev/null +++ b/web3/_utils/module_testing/offchain_lookup_contract.py @@ -0,0 +1,104 @@ +import json + +# contract source at .contract_sources/OffchainLookup.sol +OFFCHAIN_LOOKUP_BYTECODE = "608060405260405180604001604052806040518060600160405280602c815260200162000ec9602c9139815260200160405180606001604052806025815260200162000ef56025913981525060009060026200005d92919062000072565b503480156200006b57600080fd5b506200025b565b828054828255906000526020600020908101928215620000c6579160200282015b82811115620000c5578251829080519060200190620000b4929190620000d9565b509160200191906001019062000093565b5b509050620000d591906200016a565b5090565b828054620000e79062000226565b90600052602060002090601f0160209004810192826200010b576000855562000157565b82601f106200012657805160ff191683800117855562000157565b8280016001018555821562000157579182015b828111156200015657825182559160200191906001019062000139565b5b50905062000166919062000192565b5090565b5b808211156200018e5760008181620001849190620001b1565b506001016200016b565b5090565b5b80821115620001ad57600081600090555060010162000193565b5090565b508054620001bf9062000226565b6000825580601f10620001d35750620001f4565b601f016020900490600052602060002090810190620001f3919062000192565b5b50565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600060028204905060018216806200023f57607f821691505b602082108103620002555762000254620001f7565b5b50919050565b610c5e806200026b6000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806309a3c01b146100465780636337ed5814610064578063da96d05a14610094575b600080fd5b61004e6100c4565b60405161005b9190610424565b60405180910390f35b61007e600480360381019061007991906104bf565b610114565b60405161008b9190610424565b60405180910390f35b6100ae60048036038101906100a9919061050c565b610202565b6040516100bb9190610424565b60405180910390f35b606080306000826309a3c01b60e01b846040517f556f183000000000000000000000000000000000000000000000000000000000815260040161010b9594939291906107d5565b60405180910390fd5b606060008383810190610127919061096d565b90507fd9bdd1345ca2a00d0c1413137c1b2b1d0a35e5b0e11508f3b3eff856286af0758160405160200161015b91906109fd565b60405160208183030381529060405280519060200120146101b1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101a890610a71565b60405180910390fd5b306000858563da96d05a60e01b88886040517f556f18300000000000000000000000000000000000000000000000000000000081526004016101f99796959493929190610abe565b60405180910390fd5b606060008585810190610215919061096d565b90507faed76f463930323372899e36460e078e5292aac45f645bbe567be6fca83ede108160405160200161024991906109fd565b604051602081830303815290604052805190602001201461029f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161029690610b9c565b60405180910390fd5b600084848101906102b0919061096d565b90507fd9bdd1345ca2a00d0c1413137c1b2b1d0a35e5b0e11508f3b3eff856286af075816040516020016102e491906109fd565b604051602081830303815290604052805190602001201461033a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161033190610c08565b60405180910390fd5b86868080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505092505050949350505050565b600081519050919050565b600082825260208201905092915050565b60005b838110156103c55780820151818401526020810190506103aa565b838111156103d4576000848401525b50505050565b6000601f19601f8301169050919050565b60006103f68261038b565b6104008185610396565b93506104108185602086016103a7565b610419816103da565b840191505092915050565b6000602082019050818103600083015261043e81846103eb565b905092915050565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b60008083601f84011261047f5761047e61045a565b5b8235905067ffffffffffffffff81111561049c5761049b61045f565b5b6020830191508360018202830111156104b8576104b7610464565b5b9250929050565b600080602083850312156104d6576104d5610450565b5b600083013567ffffffffffffffff8111156104f4576104f3610455565b5b61050085828601610469565b92509250509250929050565b6000806000806040858703121561052657610525610450565b5b600085013567ffffffffffffffff81111561054457610543610455565b5b61055087828801610469565b9450945050602085013567ffffffffffffffff81111561057357610572610455565b5b61057f87828801610469565b925092505092959194509250565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006105b88261058d565b9050919050565b6105c8816105ad565b82525050565b600081549050919050565b600082825260208201905092915050565b60008190508160005260206000209050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061064657607f821691505b602082108103610659576106586105ff565b5b50919050565b600082825260208201905092915050565b60008190508160005260206000209050919050565b600081546106928161062e565b61069c818661065f565b945060018216600081146106b757600181146106c9576106fc565b60ff19831686526020860193506106fc565b6106d285610670565b60005b838110156106f4578154818901526001820191506020810190506106d5565b808801955050505b50505092915050565b60006107118383610685565b905092915050565b6000600182019050919050565b6000610731826105ce565b61073b81856105d9565b93508360208202850161074d856105ea565b8060005b85811015610788578484038952816107698582610705565b945061077483610719565b925060208a01995050600181019050610751565b50829750879550505050505092915050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b6107cf8161079a565b82525050565b600060a0820190506107ea60008301886105bf565b81810360208301526107fc8187610726565b9050818103604083015261081081866103eb565b905061081f60608301856107c6565b818103608083015261083181846103eb565b90509695505050505050565b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b61087a826103da565b810181811067ffffffffffffffff8211171561089957610898610842565b5b80604052505050565b60006108ac610446565b90506108b88282610871565b919050565b600067ffffffffffffffff8211156108d8576108d7610842565b5b6108e1826103da565b9050602081019050919050565b82818337600083830152505050565b600061091061090b846108bd565b6108a2565b90508281526020810184848401111561092c5761092b61083d565b5b6109378482856108ee565b509392505050565b600082601f8301126109545761095361045a565b5b81356109648482602086016108fd565b91505092915050565b60006020828403121561098357610982610450565b5b600082013567ffffffffffffffff8111156109a1576109a0610455565b5b6109ad8482850161093f565b91505092915050565b600081519050919050565b600081905092915050565b60006109d7826109b6565b6109e181856109c1565b93506109f18185602086016103a7565b80840191505092915050565b6000610a0982846109cc565b915081905092915050565b600082825260208201905092915050565b7f7465737420646174612076616c69646174696f6e206661696c65642e00000000600082015250565b6000610a5b601c83610a14565b9150610a6682610a25565b602082019050919050565b60006020820190508181036000830152610a8a81610a4e565b9050919050565b6000610a9d8385610396565b9350610aaa8385846108ee565b610ab3836103da565b840190509392505050565b600060a082019050610ad3600083018a6105bf565b8181036020830152610ae58189610726565b90508181036040830152610afa818789610a91565b9050610b0960608301866107c6565b8181036080830152610b1c818486610a91565b905098975050505050505050565b7f68747470207265717565737420726573756c742076616c69646174696f6e206660008201527f61696c65642e0000000000000000000000000000000000000000000000000000602082015250565b6000610b86602683610a14565b9150610b9182610b2a565b604082019050919050565b60006020820190508181036000830152610bb581610b79565b9050919050565b7f6578747261446174612076616c69646174696f6e206661696c65642e00000000600082015250565b6000610bf2601c83610a14565b9150610bfd82610bbc565b602082019050919050565b60006020820190508181036000830152610c2181610be5565b905091905056fea2646970667358221220528c32029f8724a4e2b6a2a469880824c952eae5971f18628559629192c102b164736f6c634300080d003368747470733a2f2f776562332e70792f676174657761792f7b73656e6465727d2f7b646174617d2e6a736f6e68747470733a2f2f776562332e70792f676174657761792f7b73656e6465727d2e6a736f6e" # noqa: E501 +OFFCHAIN_LOOKUP_BYTECODE_RUNTIME = "608060405234801561001057600080fd5b50600436106100415760003560e01c806309a3c01b146100465780636337ed5814610064578063da96d05a14610094575b600080fd5b61004e6100c4565b60405161005b9190610424565b60405180910390f35b61007e600480360381019061007991906104bf565b610114565b60405161008b9190610424565b60405180910390f35b6100ae60048036038101906100a9919061050c565b610202565b6040516100bb9190610424565b60405180910390f35b606080306000826309a3c01b60e01b846040517f556f183000000000000000000000000000000000000000000000000000000000815260040161010b9594939291906107d5565b60405180910390fd5b606060008383810190610127919061096d565b90507fd9bdd1345ca2a00d0c1413137c1b2b1d0a35e5b0e11508f3b3eff856286af0758160405160200161015b91906109fd565b60405160208183030381529060405280519060200120146101b1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101a890610a71565b60405180910390fd5b306000858563da96d05a60e01b88886040517f556f18300000000000000000000000000000000000000000000000000000000081526004016101f99796959493929190610abe565b60405180910390fd5b606060008585810190610215919061096d565b90507faed76f463930323372899e36460e078e5292aac45f645bbe567be6fca83ede108160405160200161024991906109fd565b604051602081830303815290604052805190602001201461029f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161029690610b9c565b60405180910390fd5b600084848101906102b0919061096d565b90507fd9bdd1345ca2a00d0c1413137c1b2b1d0a35e5b0e11508f3b3eff856286af075816040516020016102e491906109fd565b604051602081830303815290604052805190602001201461033a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161033190610c08565b60405180910390fd5b86868080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505092505050949350505050565b600081519050919050565b600082825260208201905092915050565b60005b838110156103c55780820151818401526020810190506103aa565b838111156103d4576000848401525b50505050565b6000601f19601f8301169050919050565b60006103f68261038b565b6104008185610396565b93506104108185602086016103a7565b610419816103da565b840191505092915050565b6000602082019050818103600083015261043e81846103eb565b905092915050565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b60008083601f84011261047f5761047e61045a565b5b8235905067ffffffffffffffff81111561049c5761049b61045f565b5b6020830191508360018202830111156104b8576104b7610464565b5b9250929050565b600080602083850312156104d6576104d5610450565b5b600083013567ffffffffffffffff8111156104f4576104f3610455565b5b61050085828601610469565b92509250509250929050565b6000806000806040858703121561052657610525610450565b5b600085013567ffffffffffffffff81111561054457610543610455565b5b61055087828801610469565b9450945050602085013567ffffffffffffffff81111561057357610572610455565b5b61057f87828801610469565b925092505092959194509250565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006105b88261058d565b9050919050565b6105c8816105ad565b82525050565b600081549050919050565b600082825260208201905092915050565b60008190508160005260206000209050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061064657607f821691505b602082108103610659576106586105ff565b5b50919050565b600082825260208201905092915050565b60008190508160005260206000209050919050565b600081546106928161062e565b61069c818661065f565b945060018216600081146106b757600181146106c9576106fc565b60ff19831686526020860193506106fc565b6106d285610670565b60005b838110156106f4578154818901526001820191506020810190506106d5565b808801955050505b50505092915050565b60006107118383610685565b905092915050565b6000600182019050919050565b6000610731826105ce565b61073b81856105d9565b93508360208202850161074d856105ea565b8060005b85811015610788578484038952816107698582610705565b945061077483610719565b925060208a01995050600181019050610751565b50829750879550505050505092915050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b6107cf8161079a565b82525050565b600060a0820190506107ea60008301886105bf565b81810360208301526107fc8187610726565b9050818103604083015261081081866103eb565b905061081f60608301856107c6565b818103608083015261083181846103eb565b90509695505050505050565b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b61087a826103da565b810181811067ffffffffffffffff8211171561089957610898610842565b5b80604052505050565b60006108ac610446565b90506108b88282610871565b919050565b600067ffffffffffffffff8211156108d8576108d7610842565b5b6108e1826103da565b9050602081019050919050565b82818337600083830152505050565b600061091061090b846108bd565b6108a2565b90508281526020810184848401111561092c5761092b61083d565b5b6109378482856108ee565b509392505050565b600082601f8301126109545761095361045a565b5b81356109648482602086016108fd565b91505092915050565b60006020828403121561098357610982610450565b5b600082013567ffffffffffffffff8111156109a1576109a0610455565b5b6109ad8482850161093f565b91505092915050565b600081519050919050565b600081905092915050565b60006109d7826109b6565b6109e181856109c1565b93506109f18185602086016103a7565b80840191505092915050565b6000610a0982846109cc565b915081905092915050565b600082825260208201905092915050565b7f7465737420646174612076616c69646174696f6e206661696c65642e00000000600082015250565b6000610a5b601c83610a14565b9150610a6682610a25565b602082019050919050565b60006020820190508181036000830152610a8a81610a4e565b9050919050565b6000610a9d8385610396565b9350610aaa8385846108ee565b610ab3836103da565b840190509392505050565b600060a082019050610ad3600083018a6105bf565b8181036020830152610ae58189610726565b90508181036040830152610afa818789610a91565b9050610b0960608301866107c6565b8181036080830152610b1c818486610a91565b905098975050505050505050565b7f68747470207265717565737420726573756c742076616c69646174696f6e206660008201527f61696c65642e0000000000000000000000000000000000000000000000000000602082015250565b6000610b86602683610a14565b9150610b9182610b2a565b604082019050919050565b60006020820190508181036000830152610bb581610b79565b9050919050565b7f6578747261446174612076616c69646174696f6e206661696c65642e00000000600082015250565b6000610bf2601c83610a14565b9150610bfd82610bbc565b602082019050919050565b60006020820190508181036000830152610c2181610be5565b905091905056fea2646970667358221220528c32029f8724a4e2b6a2a469880824c952eae5971f18628559629192c102b164736f6c634300080d0033" # noqa: E501 +OFFCHAIN_LOOKUP_ABI = json.loads('''[ + { + "inputs": [ + { + "internalType": "address", + "name": "sender", "type": "address" + }, + { + "internalType": "string[]", + "name": "urls", + "type": "string[]" + }, + { + "internalType": "bytes", + "name": "callData", + "type": "bytes"}, + { + "internalType": "bytes4", + "name": "callbackFunction", + "type":"bytes4" + }, + { + "internalType": "bytes", + "name": "extraData", + "type": "bytes" + } + ], + "name": "OffchainLookup", + "type": "error" + }, + { + "inputs": [], + "name": "continuousOffchainLookup", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type":"bytes" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "testOffchainLookupData", + "outputs": [ + { + "internalType": "bytes", + "name": "", "type": "bytes" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "specifiedDataFromTest", + "type": "bytes" + } + ], + "name": "testOffchainLookup", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "result", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "extraData", + "type": "bytes" + } + ], + "name": "testOffchainLookupWithProof", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } +]''') diff --git a/web3/_utils/module_testing/utils.py b/web3/_utils/module_testing/utils.py new file mode 100644 index 0000000000..480b3f3fda --- /dev/null +++ b/web3/_utils/module_testing/utils.py @@ -0,0 +1,156 @@ +import time +from typing import ( + TYPE_CHECKING, + Any, + Dict, + Generator, + Literal, + Sequence, + Union, +) + +from aiohttp import ( + ClientResponse, + ClientSession, + ClientTimeout, +) +from eth_typing import ( + ChecksumAddress, + HexStr, +) +from eth_utils import ( + is_same_address, +) +from hexbytes import ( + HexBytes, +) +import requests +from requests import ( + Response, +) + +from web3.types import ( + BlockData, + LogReceipt, +) + +if TYPE_CHECKING: + from web3 import Web3 # noqa: F401 + from _pytest.monkeypatch import MonkeyPatch # noqa: F401 + + +def mine_pending_block(w3: "Web3") -> None: + timeout = 10 + + w3.geth.miner.start() # type: ignore + start = time.time() + while time.time() < start + timeout: + if len(w3.eth.get_block('pending')['transactions']) == 0: + break + w3.geth.miner.stop() # type: ignore + + +def assert_contains_log( + result: Sequence[LogReceipt], + block_with_txn_with_log: BlockData, + emitter_contract_address: ChecksumAddress, + txn_hash_with_log: HexStr, +) -> None: + assert len(result) == 1 + log_entry = result[0] + assert log_entry['blockNumber'] == block_with_txn_with_log['number'] + assert log_entry['blockHash'] == block_with_txn_with_log['hash'] + assert log_entry['logIndex'] == 0 + assert is_same_address(log_entry['address'], emitter_contract_address) + assert log_entry['transactionIndex'] == 0 + assert log_entry['transactionHash'] == HexBytes(txn_hash_with_log) + + +def mock_offchain_lookup_request_response( + monkeypatch: "MonkeyPatch", + http_method: Literal['GET', 'POST'] = 'GET', + mocked_request_url: str = None, + mocked_status_code: int = 200, + mocked_json_data: str = '0x', + + # required only for POST validation: + sender: str = None, + calldata: str = None, +) -> None: + class MockedResponse: + status_code = mocked_status_code + + @staticmethod + def json() -> Dict[str, str]: return {'data': mocked_json_data} # noqa: E704 + + @staticmethod + def raise_for_status() -> None: raise Exception("called raise_for_status()") # noqa: E704 + + def _mock_specific_request( + *args: Any, **kwargs: Any + ) -> Union[Response, MockedResponse]: + # mock response only to specified url while validating appropriate fields + if args[1] == mocked_request_url: + assert kwargs['timeout'] == 10 + if http_method.upper() == 'POST': + assert kwargs['data'] == {'data': calldata, 'sender': sender} + return MockedResponse() + + # else, make a normal request (no mocking) + session = requests.Session() + result = session.request( + method=http_method.upper(), + url=args[1], + **kwargs, + ) + session.close() + return result + + monkeypatch.setattr(f'requests.Session.{http_method.lower()}', _mock_specific_request) + + +# -- async -- # + +def mock_async_offchain_lookup_request_response( + monkeypatch: "MonkeyPatch", + http_method: Literal['GET', 'POST'] = 'GET', + mocked_request_url: str = None, + mocked_status_code: int = 200, + mocked_json_data: str = '0x', + + # required only for POST validation: + sender: str = None, + calldata: str = None, +) -> None: + class AsyncMockedResponse: + status = mocked_status_code + + def __await__(self) -> Generator[Any, Any, Any]: + yield + return self + + @staticmethod + async def json() -> Dict[str, str]: return {'data': mocked_json_data} # noqa: E704 + + @staticmethod + def raise_for_status() -> None: raise Exception("called raise_for_status()") # noqa: E501, E704 + + async def _mock_specific_request( + *args: Any, **kwargs: Any + ) -> Union[ClientResponse, AsyncMockedResponse]: + # mock response only to specified url while validating appropriate fields + if args[1] == mocked_request_url: + assert kwargs['timeout'] == ClientTimeout(10) + if http_method.upper() == 'post': + assert kwargs['data'] == {'data': calldata, 'sender': sender} + return AsyncMockedResponse() + + # else, make a normal request (no mocking) + async with ClientSession(raise_for_status=True) as session: + return await session.request( + method=http_method.upper(), + url=args[1], + **kwargs, + ) + + monkeypatch.setattr(f'aiohttp.ClientSession.{http_method.lower()}', _mock_specific_request) diff --git a/web3/providers/eth_tester/defaults.py b/web3/providers/eth_tester/defaults.py index 9f67523935..466e64396e 100644 --- a/web3/providers/eth_tester/defaults.py +++ b/web3/providers/eth_tester/defaults.py @@ -79,9 +79,9 @@ def call_eth_tester( return getattr(eth_tester, fn_name)(*fn_args, **fn_kwargs) except TransactionFailed as e: possible_data = e.args[0] - if isinstance(possible_data, str) and possible_data[:10] == 'b"Uo\\x180\\': + if isinstance(possible_data, str) and possible_data[2:10] == 'Uo\\x180\\': # EIP-3668 | CCIP Read - # b"Uo\\x180\\" is the function selector for: + # b"Uo\x180" is the first 4 bytes of the keccak hash for: # OffchainLookup(address,string[],bytes,bytes4,bytes) parsed_data_as_bytes = ast.literal_eval(possible_data) data_payload = parsed_data_as_bytes[4:] # everything but the function selector