Skip to content

Commit

Permalink
Refactor transferdomain tx (#2026)
Browse files Browse the repository at this point in the history
* Refactor transferdomain message and rpc

* Add test for multiple transfer and mixed transfers

* Add comment note

* Squashed commit of the following:

commit 9cc4f21
Author: Peter John Bushnell <[email protected]>
Date:   Wed Jun 7 08:21:57 2023 +0100

    Move EVM state changes to outside Connect/DisconnectBlock (#2032)

    * Demo work in progress code

    * Add iter method to keep transaction in queue instead of draining

    * Remove print from test

    * Rename iter to get_cloned_vec

    * Use get_cloned_vec

    * Update code after merge

    ---------

    Co-authored-by: jouzo <[email protected]>

commit bba09e5
Author: Peter John Bushnell <[email protected]>
Date:   Wed Jun 7 06:52:30 2023 +0100

    Include EVM mnview in rollback. Convert miner fee to Sats. (#1999)

    * Convert miner fee to Sats

    * Move evm_finalize to ProcessDefi and include mnview changes in rollback

commit 3208586
Author: canonbrother <[email protected]>
Date:   Wed Jun 7 11:10:04 2023 +0800

    refactor(workflows): move `./scripts/fixtures.sh` to `.github` (#2030)

    * move scripts/fixtures.sh to .github

    * update bob addr to checksum addr

commit 571ae53
Author: Shoham Chakraborty <[email protected]>
Date:   Tue Jun 6 18:42:42 2023 +0800

    evm: Support contracts in functional tests (#2023)

    * Add contract compilation and interaction to Python tests

    * Fix path

    * Clean up test

    * Change function name

    * Refactor to EVMProvider and KeyPair

    * Move files to test_framework

    * Add EVMProvider to TestNode

    * Add static from_node method to KeyPair

    * Add static from_file method to EVMContract

    * Add static from_node method to EVMProvider

    * Remove web3 checksum

* Strip out validation of transferdomain as pure functions.

* Fix conversion

* Fix rpc command

* Update tests for new TransferDomain values

---------

Co-authored-by: Prasanna Loganathar <[email protected]>
Co-authored-by: Peter Bushnell <[email protected]>
  • Loading branch information
3 people authored Jun 9, 2023
1 parent f02557d commit 35d2ff2
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/masternodes/rpc_accounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,7 @@ UniValue transferdomain(const JSONRPCRequest& request) {
const auto auth = GetScriptForDestination(PKHash(key.GetID()));
auths.insert(auth);
} else
throw JSONRPCError(RPC_INVALID_PARAMETER,"Invalid parameters, src argument \"domain\" must be either 1 (DFI token to EVM) or 2 (EVM to DFI token)");
throw JSONRPCError(RPC_INVALID_PARAMETER,strprintf("Invalid parameters, src argument \"domain\" must be either %d (DFI token to EVM) or %d (EVM to DFI token)", static_cast<uint8_t>(VMDomain::DVM), static_cast<uint8_t>(VMDomain::EVM)));

if (!srcObj["data"].isNull())
src.data.assign(srcObj["data"].getValStr().begin(), srcObj["data"].getValStr().end());
Expand Down
160 changes: 134 additions & 26 deletions test/functional/feature_evm.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/functional/feature_evm_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def run_test(self):
key_pair = KeyPair.from_node(node)
address = key_pair.address

node.transferdomain(1, {self.address: ["50@DFI"]}, {address: ["50@DFI"]})
node.transferdomain([{"src": {"address":self.address, "amount":"50@DFI", "domain": 2}, "dst":{"address":address, "amount":"50@DFI", "domain": 3}}])
node.generate(1)

evm_contract = EVMContract.from_file("SimpleStorage.sol", "Test").compile()
Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_evm_rollback.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def test_rollback_transactions(self):
def run_test(self):
self.setup()

self.nodes[0].transferdomain(1,{self.address:["100@DFI"]}, {self.creationAddress:["100@DFI"]})
self.nodes[0].transferdomain(1,{self.address:["100@DFI"]}, {self.ethAddress:["100@DFI"]})
self.nodes[0].transferdomain([{"src": {"address":self.address, "amount":"100@DFI", "domain": 2}, "dst":{"address":self.creationAddress, "amount":"100@DFI", "domain": 3}}])
self.nodes[0].transferdomain([{"src": {"address":self.address, "amount":"100@DFI", "domain": 2}, "dst":{"address":self.ethAddress, "amount":"100@DFI", "domain": 3}}])
self.nodes[0].generate(1)

self.test_rollback_block()
Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_evm_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_address_state(self, address):

blockNumber = self.nodes[0].eth_blockNumber()

self.nodes[0].transferdomain(1,{self.address:["50@DFI"]}, {self.ethAddress:["50@DFI"]})
self.nodes[0].transferdomain([{"src": {"address":self.address, "amount":"50@DFI", "domain": 2}, "dst":{"address":self.ethAddress, "amount":"50@DFI", "domain": 3}}])
self.nodes[0].generate(1)

balance = self.nodes[0].eth_getBalance(address, "latest")
Expand Down Expand Up @@ -162,7 +162,7 @@ def run_test(self):

self.test_accounts()

self.nodes[0].transferdomain(1,{self.address:["100@DFI"]}, {self.ethAddress:["100@DFI"]})
self.nodes[0].transferdomain([{"src": {"address":self.address, "amount":"100@DFI", "domain": 2}, "dst":{"address":self.ethAddress, "amount":"100@DFI", "domain": 3}}])
self.nodes[0].generate(1)

self.test_address_state(self.ethAddress) # TODO test smart contract
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_evm_rpc_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def setup(self):
self.nodes[0].setgov({"ATTRIBUTES": {'v0/params/feature/evm': 'true'}})
self.nodes[0].generate(1)

self.nodes[0].transferdomain(1,{self.address:["50@DFI"]}, {self.ethAddress:["50@DFI"]})
self.nodes[0].transferdomain([{"src": {"address":self.address, "amount":"50@DFI", "domain": 2}, "dst":{"address":self.ethAddress, "amount":"50@DFI", "domain": 3}}])
self.nodes[0].generate(1)

balance = self.nodes[0].eth_getBalance(self.ethAddress, "latest")
Expand Down
8 changes: 4 additions & 4 deletions test/functional/feature_evm_smart_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def setup(self):

def test_deploy_smart_contract(self):
# deploy smart contract
self.nodes[0].evmrawtx(rawTx)
self.nodes[0].eth_sendRawTransaction(rawTx)
self.nodes[0].generate(1)

# get smart contract address
Expand All @@ -95,7 +95,7 @@ def test_smart_contract_address_state_balance(self):
balance = self.nodes[0].eth_getBalance(self.smartContractAddress)
assert_equal(balance, int_to_eth_u256(0))

self.nodes[0].transferdomain(1,{self.address:["50@DFI"]}, {self.smartContractAddress:["50@DFI"]})
self.nodes[0].transferdomain([{"src": {"address":self.address, "amount":"50@DFI", "domain": 2}, "dst":{"address":self.smartContractAddress, "amount":"50@DFI", "domain": 3}}])
self.nodes[0].generate(1)

balance = self.nodes[0].eth_getBalance(self.smartContractAddress, "latest")
Expand All @@ -112,7 +112,7 @@ def test_smart_contract_address_state_storage(self):

# Call smart contract
callRawTx = "f8ca018502540be400832dc6c094e27a95f0d6fafa131927ac50861a4190f5a9c60b80b864131a06800000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20576f726c6421000000000000000000000000000000000000002aa06e2e1dc55471cbd7ec4b0f38822152b2dfb1c31f9f7bb17f0581e81b7ab1d978a05fef62334fec720c614c138d11b78f855cd0f53ad44b2d86ff1ee68c04cfbb65"
self.nodes[0].evmrawtx(callRawTx)
self.nodes[0].eth_sendRawTransaction(callRawTx)
self.nodes[0].generate(1)

storage = self.nodes[0].eth_getStorageAt(self.smartContractAddress, "0x0", "latest")
Expand All @@ -124,7 +124,7 @@ def test_smart_contract_address_state_storage(self):
def run_test(self):
self.setup()

self.nodes[0].transferdomain(1,{self.address:["100@DFI"]}, {self.creationAddress:["100@DFI"]})
self.nodes[0].transferdomain([{"src": {"address":self.address, "amount":"100@DFI", "domain": 2}, "dst":{"address":self.creationAddress, "amount":"100@DFI", "domain": 3}}])
self.nodes[0].generate(1)

self.test_deploy_smart_contract()
Expand Down

0 comments on commit 35d2ff2

Please sign in to comment.