commit c76f6a5549df3f071eff5dd2da6c349796bc73fd
parent 60bc54933946b1c34bc5a0fd1b85df7b9877823b
Author: lash <dev@holbrook.no>
Date: Mon, 27 Mar 2023 20:42:48 +0100
Add state change example on verify
Diffstat:
5 files changed, 79 insertions(+), 10 deletions(-)
diff --git a/python/eth_offline/data/Offline.bin b/python/eth_offline/data/Offline.bin
@@ -1 +1 @@
-608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550611202806100606000396000f3fe608060405234801561001057600080fd5b506004361061005e576000357c0100000000000000000000000000000000000000000000000000000000900480631ecc95c8146100635780633859b9fb14610093578063ce606ee0146100c3575b600080fd5b61007d60048036038101906100789190610ba7565b6100e1565b60405161008a9190610c3a565b60405180910390f35b6100ad60048036038101906100a89190610cb3565b6101ac565b6040516100ba9190610c3a565b60405180910390f35b6100cb6102cb565b6040516100d89190610d1e565b60405180910390f35b600060606000806100f1866102ef565b9250828051906020012091506101078286610555565b90503073ffffffffffffffffffffffffffffffffffffffff16633859b9fb82886040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401610160929190610db8565b602060405180830381865afa15801561017d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101a19190610e14565b935050505092915050565b60006101b6610a13565b6101bf836105c4565b9050600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1603610230576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161022790610e9e565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff16816000015173ffffffffffffffffffffffffffffffffffffffff16036102725760009150506102c5565b8373ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16149150505b92915050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b606080600080845160166103039190610ef7565b67ffffffffffffffff81111561031c5761031b610a7c565b5b6040519080825280601f01601f19166020018201604052801561034e5781602001600182028036833780820191505090505b50925060197f0100000000000000000000000000000000000000000000000000000000000000028360008151811061038957610388610f2b565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060029150306c0100000000000000000000000002905060005b6014811015610470578181601481106103ed576103ec610f2b565b5b1a7f01000000000000000000000000000000000000000000000000000000000000000284848361041d9190610ef7565b8151811061042e5761042d610f2b565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061046890610f5a565b9150506103d1565b5060148261047e9190610ef7565b915060005b85518110156105495785818151811061049f5761049e610f2b565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f0100000000000000000000000000000000000000000000000000000000000000028484836104f69190610ef7565b8151811061050757610506610f2b565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061054190610f5a565b915050610483565b50829350505050919050565b600080600080610564856109ab565b9250925092506001868285856040516000815260200160405260405161058d9493929190610fd7565b6020604051602081039080840390855afa1580156105af573d6000803e3d6000fd5b50505060206040510351935050505092915050565b6105cc610a13565b606080606060548551146105e2575050506109a6565b601467ffffffffffffffff8111156105fd576105fc610a7c565b5b6040519080825280601f01601f19166020018201604052801561062f5781602001600182028036833780820191505090505b509250602067ffffffffffffffff81111561064d5761064c610a7c565b5b6040519080825280601f01601f19166020018201604052801561067f5781602001600182028036833780820191505090505b509050602067ffffffffffffffff81111561069d5761069c610a7c565b5b6040519080825280601f01601f1916602001820160405280156106cf5781602001600182028036833780820191505090505b50915060005b8351811015610790578581815181106106f1576106f0610f2b565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f01000000000000000000000000000000000000000000000000000000000000000284828151811061074e5761074d610f2b565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061078890610f5a565b9150506106d5565b5060005b602081101561085b57856014826107ab9190610ef7565b815181106107bc576107bb610f2b565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f01000000000000000000000000000000000000000000000000000000000000000283828151811061081957610818610f2b565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061085390610f5a565b915050610794565b5060005b602081101561092657856034826108769190610ef7565b8151811061088757610886610f2b565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f0100000000000000000000000000000000000000000000000000000000000000028282815181106108e4576108e3610f2b565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061091e90610f5a565b91505061085f565b50826109319061107d565b6c010000000000000000000000009004846000019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505081610982906110f9565b84602001818152505080610995906110f9565b600190048460400181815250505050505b919050565b600080600060418451146109f4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109eb906111ac565b60405180910390fd5b6020840151925060408401519150606084015160001a90509193909250565b6040518060600160405280600073ffffffffffffffffffffffffffffffffffffffff16815260200160008019168152602001600081525090565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610ab482610a6b565b810181811067ffffffffffffffff82111715610ad357610ad2610a7c565b5b80604052505050565b6000610ae6610a4d565b9050610af28282610aab565b919050565b600067ffffffffffffffff821115610b1257610b11610a7c565b5b610b1b82610a6b565b9050602081019050919050565b82818337600083830152505050565b6000610b4a610b4584610af7565b610adc565b905082815260208101848484011115610b6657610b65610a66565b5b610b71848285610b28565b509392505050565b600082601f830112610b8e57610b8d610a61565b5b8135610b9e848260208601610b37565b91505092915050565b60008060408385031215610bbe57610bbd610a57565b5b600083013567ffffffffffffffff811115610bdc57610bdb610a5c565b5b610be885828601610b79565b925050602083013567ffffffffffffffff811115610c0957610c08610a5c565b5b610c1585828601610b79565b9150509250929050565b60008115159050919050565b610c3481610c1f565b82525050565b6000602082019050610c4f6000830184610c2b565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610c8082610c55565b9050919050565b610c9081610c75565b8114610c9b57600080fd5b50565b600081359050610cad81610c87565b92915050565b60008060408385031215610cca57610cc9610a57565b5b6000610cd885828601610c9e565b925050602083013567ffffffffffffffff811115610cf957610cf8610a5c565b5b610d0585828601610b79565b9150509250929050565b610d1881610c75565b82525050565b6000602082019050610d336000830184610d0f565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610d73578082015181840152602081019050610d58565b60008484015250505050565b6000610d8a82610d39565b610d948185610d44565b9350610da4818560208601610d55565b610dad81610a6b565b840191505092915050565b6000604082019050610dcd6000830185610d0f565b8181036020830152610ddf8184610d7f565b90509392505050565b610df181610c1f565b8114610dfc57600080fd5b50565b600081519050610e0e81610de8565b92915050565b600060208284031215610e2a57610e29610a57565b5b6000610e3884828501610dff565b91505092915050565b600082825260208201905092915050565b7f4552525f5a45524f5f56414c494441544f520000000000000000000000000000600082015250565b6000610e88601283610e41565b9150610e9382610e52565b602082019050919050565b60006020820190508181036000830152610eb781610e7b565b9050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610f0282610ebe565b9150610f0d83610ebe565b9250828201905080821115610f2557610f24610ec8565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000610f6582610ebe565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610f9757610f96610ec8565b5b600182019050919050565b6000819050919050565b610fb581610fa2565b82525050565b600060ff82169050919050565b610fd181610fbb565b82525050565b6000608082019050610fec6000830187610fac565b610ff96020830186610fc8565b6110066040830185610fac565b6110136060830184610fac565b95945050505050565b6000819050602082019050919050565b60007fffffffffffffffffffffffffffffffffffffffff00000000000000000000000082169050919050565b6000611064825161102c565b80915050919050565b60008160020a8302905092915050565b600061108882610d39565b826110928461101c565b905061109d81611058565b925060148210156110dd576110d87fffffffffffffffffffffffffffffffffffffffff0000000000000000000000008360140360080261106d565b831692505b5050919050565b60006110f08251610fa2565b80915050919050565b600061110482610d39565b8261110e8461101c565b9050611119816110e4565b92506020821015611159576111547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8360200360080261106d565b831692505b5050919050565b7f696e76616c6964207369676e6174757265206c656e6774680000000000000000600082015250565b6000611196601883610e41565b91506111a182611160565b602082019050919050565b600060208201905081810360008301526111c581611189565b905091905056fea26469706673582212207ae8dc44a3ce9f283d9d464907bd95ad3561172a33c9f30142d38568d93e17f664736f6c63430008130033
-\ No newline at end of file
+608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061136f806100606000396000f3fe608060405234801561001057600080fd5b5060043610610074576000357c0100000000000000000000000000000000000000000000000000000000900480631ecc95c8146100795780632c0b80e2146100a95780633327670c146100d9578063602f7c72146100f7578063ce606ee014610127575b600080fd5b610093600480360381019061008e9190610c7e565b610145565b6040516100a09190610d11565b60405180910390f35b6100c360048036038101906100be9190610d8a565b610210565b6040516100d09190610d11565b60405180910390f35b6100e161032f565b6040516100ee9190610dff565b60405180910390f35b610111600480360381019061010c9190610c7e565b610335565b60405161011e9190610d11565b60405180910390f35b61012f6103a2565b60405161013c9190610e29565b60405180910390f35b60006060600080610155866103c6565b92508280519060200120915061016b828661062c565b90503073ffffffffffffffffffffffffffffffffffffffff16632c0b80e282886040518363ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004016101c4929190610ec3565b602060405180830381865afa1580156101e1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102059190610f1f565b935050505092915050565b600061021a610aea565b6102238361069b565b9050600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1603610294576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161028b90610fa9565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff16816000015173ffffffffffffffffffffffffffffffffffffffff16036102d6576000915050610329565b8373ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16149150505b92915050565b60015481565b60006103418383610145565b610380576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161037790611015565b60405180910390fd5b6001600081548092919061039390611064565b91905055506001905092915050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b606080600080845160166103da91906110ac565b67ffffffffffffffff8111156103f3576103f2610b53565b5b6040519080825280601f01601f1916602001820160405280156104255781602001600182028036833780820191505090505b50925060197f010000000000000000000000000000000000000000000000000000000000000002836000815181106104605761045f6110e0565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060029150306c0100000000000000000000000002905060005b6014811015610547578181601481106104c4576104c36110e0565b5b1a7f0100000000000000000000000000000000000000000000000000000000000000028484836104f491906110ac565b81518110610505576105046110e0565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061053f90611064565b9150506104a8565b5060148261055591906110ac565b915060005b855181101561062057858181518110610576576105756110e0565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f0100000000000000000000000000000000000000000000000000000000000000028484836105cd91906110ac565b815181106105de576105dd6110e0565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061061890611064565b91505061055a565b50829350505050919050565b60008060008061063b85610a82565b925092509250600186828585604051600081526020016040526040516106649493929190611144565b6020604051602081039080840390855afa158015610686573d6000803e3d6000fd5b50505060206040510351935050505092915050565b6106a3610aea565b606080606060548551146106b957505050610a7d565b601467ffffffffffffffff8111156106d4576106d3610b53565b5b6040519080825280601f01601f1916602001820160405280156107065781602001600182028036833780820191505090505b509250602067ffffffffffffffff81111561072457610723610b53565b5b6040519080825280601f01601f1916602001820160405280156107565781602001600182028036833780820191505090505b509050602067ffffffffffffffff81111561077457610773610b53565b5b6040519080825280601f01601f1916602001820160405280156107a65781602001600182028036833780820191505090505b50915060005b8351811015610867578581815181106107c8576107c76110e0565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f010000000000000000000000000000000000000000000000000000000000000002848281518110610825576108246110e0565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061085f90611064565b9150506107ac565b5060005b6020811015610932578560148261088291906110ac565b81518110610893576108926110e0565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f0100000000000000000000000000000000000000000000000000000000000000028382815181106108f0576108ef6110e0565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061092a90611064565b91505061086b565b5060005b60208110156109fd578560348261094d91906110ac565b8151811061095e5761095d6110e0565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f0100000000000000000000000000000000000000000000000000000000000000028282815181106109bb576109ba6110e0565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806109f590611064565b915050610936565b5082610a08906111ea565b6c010000000000000000000000009004846000019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505081610a5990611266565b84602001818152505080610a6c90611266565b600190048460400181815250505050505b919050565b60008060006041845114610acb576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ac290611319565b60405180910390fd5b6020840151925060408401519150606084015160001a90509193909250565b6040518060600160405280600073ffffffffffffffffffffffffffffffffffffffff16815260200160008019168152602001600081525090565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610b8b82610b42565b810181811067ffffffffffffffff82111715610baa57610ba9610b53565b5b80604052505050565b6000610bbd610b24565b9050610bc98282610b82565b919050565b600067ffffffffffffffff821115610be957610be8610b53565b5b610bf282610b42565b9050602081019050919050565b82818337600083830152505050565b6000610c21610c1c84610bce565b610bb3565b905082815260208101848484011115610c3d57610c3c610b3d565b5b610c48848285610bff565b509392505050565b600082601f830112610c6557610c64610b38565b5b8135610c75848260208601610c0e565b91505092915050565b60008060408385031215610c9557610c94610b2e565b5b600083013567ffffffffffffffff811115610cb357610cb2610b33565b5b610cbf85828601610c50565b925050602083013567ffffffffffffffff811115610ce057610cdf610b33565b5b610cec85828601610c50565b9150509250929050565b60008115159050919050565b610d0b81610cf6565b82525050565b6000602082019050610d266000830184610d02565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610d5782610d2c565b9050919050565b610d6781610d4c565b8114610d7257600080fd5b50565b600081359050610d8481610d5e565b92915050565b60008060408385031215610da157610da0610b2e565b5b6000610daf85828601610d75565b925050602083013567ffffffffffffffff811115610dd057610dcf610b33565b5b610ddc85828601610c50565b9150509250929050565b6000819050919050565b610df981610de6565b82525050565b6000602082019050610e146000830184610df0565b92915050565b610e2381610d4c565b82525050565b6000602082019050610e3e6000830184610e1a565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610e7e578082015181840152602081019050610e63565b60008484015250505050565b6000610e9582610e44565b610e9f8185610e4f565b9350610eaf818560208601610e60565b610eb881610b42565b840191505092915050565b6000604082019050610ed86000830185610e1a565b8181036020830152610eea8184610e8a565b90509392505050565b610efc81610cf6565b8114610f0757600080fd5b50565b600081519050610f1981610ef3565b92915050565b600060208284031215610f3557610f34610b2e565b5b6000610f4384828501610f0a565b91505092915050565b600082825260208201905092915050565b7f4552525f5a45524f5f56414c494441544f520000000000000000000000000000600082015250565b6000610f93601283610f4c565b9150610f9e82610f5d565b602082019050919050565b60006020820190508181036000830152610fc281610f86565b9050919050565b7f4552525f554e5645524946494544000000000000000000000000000000000000600082015250565b6000610fff600e83610f4c565b915061100a82610fc9565b602082019050919050565b6000602082019050818103600083015261102e81610ff2565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061106f82610de6565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036110a1576110a0611035565b5b600182019050919050565b60006110b782610de6565b91506110c283610de6565b92508282019050808211156110da576110d9611035565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000819050919050565b6111228161110f565b82525050565b600060ff82169050919050565b61113e81611128565b82525050565b60006080820190506111596000830187611119565b6111666020830186611135565b6111736040830185611119565b6111806060830184611119565b95945050505050565b6000819050602082019050919050565b60007fffffffffffffffffffffffffffffffffffffffff00000000000000000000000082169050919050565b60006111d18251611199565b80915050919050565b60008160020a8302905092915050565b60006111f582610e44565b826111ff84611189565b905061120a816111c5565b9250601482101561124a576112457fffffffffffffffffffffffffffffffffffffffff000000000000000000000000836014036008026111da565b831692505b5050919050565b600061125d825161110f565b80915050919050565b600061127182610e44565b8261127b84611189565b905061128681611251565b925060208210156112c6576112c17fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff836020036008026111da565b831692505b5050919050565b7f696e76616c6964207369676e6174757265206c656e6774680000000000000000600082015250565b6000611303601883610f4c565b915061130e826112cd565b602082019050919050565b60006020820190508181036000830152611332816112f6565b905091905056fea2646970667358221220576355ede34468649e9d1e13afcc70737420597631fedabefd3accf551f2acb664736f6c63430008130033
+\ No newline at end of file
diff --git a/python/eth_offline/data/Offline.json b/python/eth_offline/data/Offline.json
@@ -1 +1 @@
-[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"contractOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_validator","type":"address"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"isOfflineValidator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"verifyOfflineRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]
+[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"contractOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"executeOfflineRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"executedTimes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_validator","type":"address"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"isOfflineValid","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"verifyOfflineRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]
diff --git a/python/tests/test_basic.py b/python/tests/test_basic.py
@@ -5,6 +5,7 @@ import unittest
# external imports
from chainlib.eth.tx import TxFactory
+from chainlib.eth.tx import TxFormat
from chainlib.eth.unittest.ethtester import EthTesterCase
from chainlib.connection import RPCConnection
from chainlib.eth.nonce import RPCNonceOracle
@@ -58,7 +59,7 @@ class TestOfflineEth(EthTesterCase):
o = j.template()
o['method'] = 'eth_call'
enc = ABIContractEncoder()
- enc.method('isOfflineValidator')
+ enc.method('isOfflineValid')
enc.typ(ABIContractType.ADDRESS)
enc.typ(ABIContractType.BYTES)
enc.address(strip_0x(self.accounts[0]))
@@ -78,7 +79,7 @@ class TestOfflineEth(EthTesterCase):
o = j.template()
o['method'] = 'eth_call'
enc = ABIContractEncoder()
- enc.method('isOfflineValidator')
+ enc.method('isOfflineValid')
enc.typ(ABIContractType.ADDRESS)
enc.typ(ABIContractType.BYTES)
enc.address(strip_0x(self.accounts[2]))
@@ -99,7 +100,7 @@ class TestOfflineEth(EthTesterCase):
o = j.template()
o['method'] = 'eth_call'
enc = ABIContractEncoder()
- enc.method('isOfflineValidator')
+ enc.method('isOfflineValid')
enc.typ(ABIContractType.ADDRESS)
enc.typ(ABIContractType.BYTES)
enc.address(strip_0x(self.accounts[0]))
@@ -153,7 +154,7 @@ class TestOfflineEth(EthTesterCase):
msg_bin = os.urandom(64)
msg_data = beneficiary_bin + msg_bin
- sig = self.signer.sign_ethereum_message(self.accounts[1], msg_data)
+ sig = self.signer.sign_validator_message(self.accounts[1], self.address, msg_data)
sig = sig[:64] + (sig[64] + 27).to_bytes(1, byteorder='big')
logg.debug('message is {} signed by {}'.format(msg_data.hex(), self.accounts[1]))
@@ -180,5 +181,64 @@ class TestOfflineEth(EthTesterCase):
self.assertEqual(int(r, 16), 0)
+ def test_execute(self):
+ beneficiary_bin = bytes.fromhex(strip_0x(self.accounts[2]))
+ msg_bin = os.urandom(64)
+ msg_data = beneficiary_bin + msg_bin
+
+ sig = self.signer.sign_validator_message(self.accounts[0], self.address, msg_data)
+ sig = sig[:64] + (sig[64] + 27).to_bytes(1, byteorder='big')
+ logg.debug('message is {} signed by {}'.format(msg_data.hex(), self.accounts[1]))
+
+ c = TxFactory(self.chain_spec)
+ j = JSONRPCRequest()
+ o = j.template()
+ o['method'] = 'eth_call'
+ enc = ABIContractEncoder()
+ enc.method('executedTimes')
+ data = add_0x(enc.get())
+ tx = c.template(self.accounts[0], self.address)
+ tx = c.set_code(tx, data)
+ o['params'].append(c.normalize(tx))
+ o['params'].append('latest')
+ o = j.finalize(o)
+ r = self.rpc.do(o)
+ r = strip_0x(r)
+ self.assertEqual(int(r, 16), 0)
+
+ nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
+ c = TxFactory(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
+ enc = ABIContractEncoder()
+ enc.method('executeOfflineRequest')
+ enc.typ(ABIContractType.BYTES)
+ enc.typ(ABIContractType.BYTES)
+ enc.bytes(msg_data.hex())
+ enc.bytes(sig.hex())
+ data = enc.get()
+ tx = c.template(self.accounts[0], self.address, use_nonce=True)
+ tx = c.set_code(tx, data)
+ (tx_hash, o) = c.finalize(tx, TxFormat.JSONRPC)
+ self.rpc.do(o)
+ o = receipt(tx_hash)
+ r = self.rpc.do(o)
+ self.assertEqual(r['status'], 1)
+
+ c = TxFactory(self.chain_spec)
+ j = JSONRPCRequest()
+ o = j.template()
+ o['method'] = 'eth_call'
+ enc = ABIContractEncoder()
+ enc.method('executedTimes')
+ data = add_0x(enc.get())
+ tx = c.template(self.accounts[0], self.address)
+ tx = c.set_code(tx, data)
+ o['params'].append(c.normalize(tx))
+ o['params'].append('latest')
+ o = j.finalize(o)
+ r = self.rpc.do(o)
+ r = strip_0x(r)
+ self.assertEqual(int(r, 16), 1)
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/solidity/Offline.sol b/solidity/Offline.sol
@@ -13,12 +13,19 @@ contract OfflineRubber is Offline {
}
address public contractOwner;
+ uint256 public executedTimes;
constructor() {
contractOwner = msg.sender;
}
- function isOfflineValidator(address _validator, bytes memory _data) external override view returns(bool) {
+ function executeOfflineRequest(bytes memory _data, bytes memory _signature) public override returns(bool) {
+ require(verifyOfflineRequest(_data, _signature), 'ERR_UNVERIFIED');
+ executedTimes++;
+ return true;
+ }
+
+ function isOfflineValid(address _validator, bytes memory _data) external override view returns(bool) {
Instruction memory instruction;
instruction = splitData(_data);
diff --git a/solidity/OfflineBase.sol b/solidity/OfflineBase.sol
@@ -4,7 +4,9 @@ pragma solidity ^0.8.0;
// Some methods are copied under other licenses, please see code comments for details
abstract contract Offline {
- function isOfflineValidator(address _validator, bytes memory _data) external virtual view returns(bool);
+ function executeOfflineRequest(bytes memory _data, bytes memory _signature) public virtual returns(bool);
+
+ function isOfflineValid(address _validator, bytes memory _data) external virtual view returns(bool);
function verifyOfflineRequest(bytes memory _data, bytes memory _signature) public view returns(bool) {
bytes memory message;
@@ -15,7 +17,7 @@ abstract contract Offline {
messageDigest = keccak256(message);
_owner = recoverSigner(messageDigest, _signature);
- return this.isOfflineValidator(_owner, _data);
+ return this.isOfflineValid(_owner, _data);
}
function toValidatorMessage(bytes memory _data) private view returns(bytes memory) {