Skip to content

Commit

Permalink
Merge branch 'master' into evm/dst20-2
Browse files Browse the repository at this point in the history
  • Loading branch information
prasannavl authored Jul 28, 2023
2 parents ec856c5 + 94fab39 commit ec1c8c1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.
51 changes: 43 additions & 8 deletions test/functional/feature_evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,29 @@ def run_test(self):
self.nodes[0].setgov({"ATTRIBUTES": {'v0/params/feature/transferdomain': 'true'}})
self.nodes[0].generate(1)

# Check error before transferdomain DVM to EVM is enabled
# Fund DFI address
txid = self.nodes[0].utxostoaccount({address: "200@DFI"})
self.nodes[0].generate(1)

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

# Deactivate transferdomain DVM to EVM
self.nodes[0].setgov({"ATTRIBUTES": {'v0/transferdomain/dvm-evm/enabled': 'false'}})
self.nodes[0].generate(1)

# Check error transferdomain DVM to EVM is enabled
assert_raises_rpc_error(-32600, "DVM to EVM is not currently enabled", self.nodes[0].transferdomain, [{"src": {"address":address, "amount":"100@DFI", "domain": 2}, "dst":{"address":eth_address, "amount":"100@DFI", "domain": 3}}])

# Activate transferdomain DVM to EVM
self.nodes[0].setgov({"ATTRIBUTES": {'v0/transferdomain/dvm-evm/enabled': 'true'}})
self.nodes[0].generate(1)

# Activate transferdomain PKHash address
self.nodes[0].setgov({"ATTRIBUTES": {'v0/transferdomain/dvm-evm/src-formats': ['bech32']}})
self.nodes[0].generate(1)

# Check transferdomain DVM to EVM before p2pkh addresses are enabled
assert_raises_rpc_error(-32600, "Src address must be a legacy or Bech32 address in case of \"DVM\" domain", self.nodes[0].transferdomain, [{"src": {"address":address, "amount":"100@DFI", "domain": 2}, "dst":{"address":eth_address, "amount":"100@DFI", "domain": 3}}])

Expand All @@ -149,6 +165,9 @@ def run_test(self):
self.nodes[0].setgov({"ATTRIBUTES": {'v0/transferdomain/dvm-evm/src-formats': ['p2pkh','bech32']}})
self.nodes[0].generate(1)

self.nodes[0].setgov({"ATTRIBUTES": {'v0/transferdomain/dvm-evm/dest-formats': ['bech32']}})
self.nodes[0].generate(1)

# Check transferdomain DVM to EVM before ERC55 addresses are enabled
assert_raises_rpc_error(-32600, 'Dst address must be an ERC55 address in case of "EVM" domain', self.nodes[0].transferdomain, [{"src": {"address":eth_address_bech32, "amount":"100@DFI", "domain": 2}, "dst":{"address":eth_address, "amount":"100@DFI", "domain": 3}}])

Expand All @@ -157,15 +176,15 @@ def run_test(self):
self.nodes[0].generate(1)

# Fund DFI address
txid = self.nodes[0].utxostoaccount({address: "200@DFI"})
txid = self.nodes[0].utxostoaccount({address: "100@DFI"})
self.nodes[0].generate(1)

# Check initial balances
dfi_balance = self.nodes[0].getaccount(address, {}, True)['0']
eth_balance = self.nodes[0].eth_getBalance(eth_address)
assert_equal(dfi_balance, Decimal('200'))
assert_equal(eth_balance, int_to_eth_u256(0))
assert_equal(len(self.nodes[0].getaccount(eth_address, {}, True)), 0)
assert_equal(eth_balance, int_to_eth_u256(100))
assert_equal(len(self.nodes[0].getaccount(eth_address, {}, True)), 1)

# Check for invalid parameters in transferdomain rpc
assert_raises_rpc_error(-5, "Eth type addresses are not valid", self.nodes[0].createrawtransaction, [{'txid': txid, 'vout': 1}], [{eth_address: 1}])
Expand All @@ -174,13 +193,21 @@ def run_test(self):
assert_raises_rpc_error(-5, "Eth type addresses are not valid", self.nodes[0].sendtoaddress, eth_address, 1)
assert_raises_rpc_error(-5, "Eth type addresses are not valid", self.nodes[0].accounttoaccount, address, {eth_address: "1@DFI"})

# Deactivate transferdomain DVM to EVM
self.nodes[0].setgov({"ATTRIBUTES": {'v0/transferdomain/evm-dvm/enabled': 'false'}})
self.nodes[0].generate(1)

# Check error before transferdomain DVM to EVM is enabled
assert_raises_rpc_error(-32600, "EVM to DVM is not currently enabled", self.nodes[0].transferdomain, [{"src": {"address":address, "amount":"100@DFI", "domain": 3}, "dst":{"address":eth_address, "amount":"100@DFI", "domain": 2}}])

# Activate transferdomain DVM to EVM
self.nodes[0].setgov({"ATTRIBUTES": {'v0/transferdomain/evm-dvm/enabled': 'true'}})
self.nodes[0].generate(1)

# Deactivate transferdomain ERC55 address
self.nodes[0].setgov({"ATTRIBUTES": {'v0/transferdomain/evm-dvm/src-formats': ['bech32']}})
self.nodes[0].generate(1)

# Check transferdomain EVM to DVM before ERC55 addresses are enabled
assert_raises_rpc_error(-32600, 'Src address must be an ERC55 address in case of "EVM" domain', self.nodes[0].transferdomain, [{"src": {"address":eth_address, "amount":"100@DFI", "domain": 3}, "dst":{"address":address, "amount":"100@DFI", "domain": 2}}])

Expand All @@ -190,6 +217,10 @@ def run_test(self):

print(self.nodes[0].getgov('ATTRIBUTES'))

# Dectivate transferdomain ERC55 address
self.nodes[0].setgov({"ATTRIBUTES": {'v0/transferdomain/evm-dvm/dest-formats': ['bech32']}})
self.nodes[0].generate(1)

# Check transferdomain EVM to DVM before P2PKH addresses are enabled
assert_raises_rpc_error(-32600, 'Dst address must be a legacy or Bech32 address in case of "DVM" domain', self.nodes[0].transferdomain, [{"src": {"address":eth_address, "amount":"100@DFI", "domain": 3}, "dst":{"address":address, "amount":"100@DFI", "domain": 2}}])

Expand All @@ -204,6 +235,10 @@ def run_test(self):
self.nodes[0].setgov({"ATTRIBUTES": {'v0/transferdomain/evm-dvm/dest-formats': ['bech32', 'p2pkh']}})
self.nodes[0].generate(1)

# Dectivate transferdomain ERC55 address
self.nodes[0].setgov({"ATTRIBUTES": {'v0/transferdomain/evm-dvm/auth-formats': ['p2pkh-erc55']}})
self.nodes[0].generate(1)

# Check transferdomain EVM to DVM before Bech32 auth is enabled
assert_raises_rpc_error(-32600, 'tx must have at least one input from account owner', self.nodes[0].transferdomain, [{"src": {"address":eth_address, "amount":"100@DFI", "domain": 3}, "dst":{"address":eth_address_bech32, "amount":"100@DFI", "domain": 2}}])

Expand All @@ -219,7 +254,7 @@ def run_test(self):
self.sync_blocks()

# Check Eth balances before transfer
assert_equal(int(self.nodes[0].eth_getBalance(eth_address)[2:], 16), 100000000000000000000)
assert_equal(int(self.nodes[0].eth_getBalance(eth_address)[2:], 16), 200000000000000000000)
assert_equal(int(self.nodes[0].eth_getBalance(to_address)[2:], 16), 0)

# Send tokens to burn address
Expand Down Expand Up @@ -287,7 +322,7 @@ def run_test(self):
assert_equal(block_txs[6], tx5)

# Check Eth balances after transfer
assert_equal(int(self.nodes[0].eth_getBalance(eth_address)[2:], 16), 93997333000000000000)
assert_equal(int(self.nodes[0].eth_getBalance(eth_address)[2:], 16), 193997333000000000000)
assert_equal(int(self.nodes[0].eth_getBalance(to_address)[2:], 16), 6000000000000000000)

# Get burn address and miner account balance after transfer
Expand Down Expand Up @@ -354,7 +389,7 @@ def run_test(self):
assert_equal(miner_before, miner_rollback)

# Check Eth balances before transfer
assert_equal(int(self.nodes[0].eth_getBalance(eth_address)[2:], 16), 100000000000000000000)
assert_equal(int(self.nodes[0].eth_getBalance(eth_address)[2:], 16), 200000000000000000000)
assert_equal(int(self.nodes[0].eth_getBalance(to_address)[2:], 16), 0)

# Test max limit of TX from a specific sender
Expand All @@ -370,7 +405,7 @@ def run_test(self):
assert_equal(len(block_txs), 64)

# Check Eth balances after transfer
assert_equal(int(self.nodes[0].eth_getBalance(eth_address)[2:], 16), 36972217000000000000)
assert_equal(int(self.nodes[0].eth_getBalance(eth_address)[2:], 16), 136972217000000000000)
assert_equal(int(self.nodes[0].eth_getBalance(to_address)[2:], 16), 63000000000000000000)

# Try and send another TX to make sure mempool has removed entires
Expand Down
10 changes: 0 additions & 10 deletions test/functional/feature_evm_transferdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ def invalid_before_fork_and_disabled(self):
self.nodes[0].setgov({"ATTRIBUTES": {'v0/params/feature/transferdomain': 'true'}})
self.nodes[0].generate(1)

# Check error before transferdomain DVM to EVM is enabled
assert_raises_rpc_error(-32600, "DVM to EVM is not currently enabled", self.nodes[0].transferdomain, [{"src": {"address":self.address, "amount":"100@DFI", "domain": 2}, "dst":{"address":self.eth_address, "amount":"100@DFI", "domain": 3}}])

# Activate transferdomain DVM to EVM
self.nodes[0].setgov({"ATTRIBUTES": {'v0/transferdomain/dvm-evm/enabled': 'true'}})
self.nodes[0].generate(1)

# Check error before transferdomain DVM to EVM is enabled
assert_raises_rpc_error(-32600, "EVM to DVM is not currently enabled", self.nodes[0].transferdomain, [{"src": {"address":self.address, "amount":"100@DFI", "domain": 3}, "dst":{"address":self.eth_address, "amount":"100@DFI", "domain": 2}}])

# Activate transferdomain DVM to EVM
self.nodes[0].setgov({"ATTRIBUTES": {'v0/transferdomain/evm-dvm/enabled': 'true',
'v0/transferdomain/dvm-evm/src-formats': ['p2pkh','bech32'],
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_setgov.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def run_test(self):
assert_raises_rpc_error(-5, "Empty version", self.nodes[0].setgov, {"ATTRIBUTES": {'': 'true'}})
assert_raises_rpc_error(-5, "Unsupported version", self.nodes[0].setgov,
{"ATTRIBUTES": {'1/token/15/payback_dfi': 'true'}})
assert_raises_rpc_error(-5, "Empty value", self.nodes[0].setgov,
assert_raises_rpc_error(-5, 'Boolean value must be either "true" or "false"', self.nodes[0].setgov,
{"ATTRIBUTES": {'v0/token/15/payback_dfi': ''}})
assert_raises_rpc_error(-5,
"Incorrect key for <type>. Object of ['<version>/<type>/ID/<key>','value'] expected",
Expand Down

0 comments on commit ec1c8c1

Please sign in to comment.