Skip to content

Commit

Permalink
chore(): fix regression of 4.0.0 beta13 (#2159)
Browse files Browse the repository at this point in the history
<!--  Thanks for sending a pull request! -->

#### What this PR does / why we need it:

#### Which issue(s) does this PR fixes?:
<!--
(Optional) Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
Fixes #

#### Additional comments?:
  • Loading branch information
canonbrother committed Oct 3, 2023
1 parent 950b21c commit 4b4724c
Show file tree
Hide file tree
Showing 8 changed files with 639 additions and 556 deletions.
1 change: 0 additions & 1 deletion apps/whale-api/__sanity__/WhaleSanityContainer.sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ describe('/rpc/getblock', () => {
difficulty: 4.656542373906925e-10,
hash: 'd744db74fb70ed42767ae028a129365fb4d7de54ba1b6575fb047490554f8a7b',
height: 0,
masternode: '0000000000000000000000000000000000000000000000000000000000000000',
mediantime: 1579045065,
merkleroot: '5615dbbb379da893dd694e02d25a7955e1b7471db55f42bbd82b5d3f5bdb8d38',
mintedBlocks: 0,
Expand Down
3 changes: 2 additions & 1 deletion apps/whale-api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ version: "3.7"

services:
defi-blockchain:
image: defi/defichain:master-b352814976
image: defi/defichain:4.0.0-beta13

ports:
- "19554:19554"
command: >
Expand Down
76 changes: 0 additions & 76 deletions contracts/TransferDomain.sol

This file was deleted.

126 changes: 126 additions & 0 deletions contracts/TransferDomainV1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// File: @openzeppelin/[email protected]/token/ERC20/IERC20.sol

// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);

/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);

/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}

interface IERC20 {
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
* @title TransferDomain
*/
contract TransferDomainV1 is IERC20Metadata {
mapping(address => uint256) private _balances;
uint256 private _totalSupply;

event Transfer(address indexed from, address indexed to, uint256 amount);
event VMTransfer(string vmAddress);

function transfer(
address from,
address payable to,
uint256 amount,
string memory vmAddress
) external {
if (to != address(this)) {
require(
address(this).balance >= amount,
"Insufficient contract balance"
);

to.transfer(amount);
}

emit Transfer(from, to, amount);
emit VMTransfer(vmAddress);
}

/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return "TransferDomain";
}

/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return "DFI";
}

/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}

function transferDST20(
address contractAddress,
address from,
address payable to,
uint256 amount,
string memory vmAddress
) external {
IERC20(contractAddress).transferFrom(from, to, amount);
emit VMTransfer(vmAddress);
}

/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}

/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe('TransferDomain', () => {
}
])
await expect(promise).rejects.toThrow(RpcApiError)
await expect(promise).rejects.toThrow(`Failed to create and sign TX: Invalid address ${dvmAddr}`)
await expect(promise).rejects.toThrow('Failed to create and sign TX: Invalid address')
})

it('(evm -> dvm) should fail if src address is not ERC55 address in case of "EVM" domain', async () => {
Expand Down Expand Up @@ -486,7 +486,7 @@ describe('TransferDomain', () => {
}
])
await expect(promise).rejects.toThrow(RpcApiError)
await expect(promise).rejects.toThrow(`Failed to create and sign TX: Invalid address ${dvmAddr}`)
await expect(promise).rejects.toThrow('Failed to create and sign TX: Invalid address')
})

it('(evm -> evm) should fail if transfer within same domain', async () => {
Expand Down Expand Up @@ -527,9 +527,8 @@ describe('TransferDomain', () => {
await expect(promise).rejects.toThrow('amount 90000.00000000 is less than 999999.00000000')
})

// TODO(canonbrother): check again here after pull the later version
it.skip('(evm -> dvm) should fail if insufficient balance', async () => {
const promise = client.account.transferDomain([
it('(evm -> dvm) should not fail if insufficient balance but tx remained in mempool', async () => {
const txid = await client.account.transferDomain([
{
src: {
address: evmAddr,
Expand All @@ -543,8 +542,12 @@ describe('TransferDomain', () => {
}
}
])
await expect(promise).rejects.toThrow(RpcApiError)
await expect(promise).rejects.toThrow(`Not enough balance in ${evmAddr} to cover "EVM" domain transfer`)
const mempool: string[] = await container.call('getrawmempool')
await container.generate(1)
const found = mempool.find((m: string) => m === txid)
expect(found).toBeDefined()

await container.call('clearmempool')
})

it('(dvm -> evm) should fail if custom (isDAT = false) token is transferred', async () => {
Expand Down Expand Up @@ -729,37 +732,6 @@ describe('TransferDomain', () => {
.toStrictEqual(new BigNumber(currentBalance).minus(3))
})

it('(dvm -> evm) should transfer domain - dToken', async () => {
const dvmAcc = await getAccountValues(client, dvmAddr)
const btcTokenId = 'BTC'
const btcBalance = dvmAcc[btcTokenId]
const txid1 = await client.account.transferDomain([
{
src: {
address: dvmAddr,
amount: '3@BTC',
domain: TransferDomainType.DVM
},
dst: {
address: evmAddr,
amount: '3@BTC',
domain: TransferDomainType.EVM
}
}
])
expect(typeof txid1).toStrictEqual('string')
expect(txid1.length).toStrictEqual(64)

await container.generate(1)

const dvmAcc1 = await getAccountValues(client, dvmAddr)
const btcBalance1 = dvmAcc1[btcTokenId]

// check: BTC balance is transferred
expect(new BigNumber(btcBalance1))
.toStrictEqual(new BigNumber(btcBalance).minus(3))
})

it('(evm -> dvm) should transfer domain - DFI', async () => {
const dvmAcc = await getAccountValues(client, dvmAddr)
const tokenId = 'DFI'
Expand Down Expand Up @@ -795,6 +767,37 @@ describe('TransferDomain', () => {
.toStrictEqual(new BigNumber(currentBalance).plus(3))
})

it('(dvm -> evm) should transfer domain - dToken', async () => {
const dvmAcc = await getAccountValues(client, dvmAddr)
const btcTokenId = 'BTC'
const btcBalance = dvmAcc[btcTokenId]
const txid1 = await client.account.transferDomain([
{
src: {
address: dvmAddr,
amount: '3@BTC',
domain: TransferDomainType.DVM
},
dst: {
address: evmAddr,
amount: '3@BTC',
domain: TransferDomainType.EVM
}
}
])
expect(typeof txid1).toStrictEqual('string')
expect(txid1.length).toStrictEqual(64)

await container.generate(1)

const dvmAcc1 = await getAccountValues(client, dvmAddr)
const btcBalance1 = dvmAcc1[btcTokenId]

// check: BTC balance is transferred
expect(new BigNumber(btcBalance1))
.toStrictEqual(new BigNumber(btcBalance).minus(3))
})

it('(evm -> dvm) should transfer domain - dToken', async () => {
const dvmAcc = await getAccountValues(client, dvmAddr)
const btcTokenId = 'BTC'
Expand Down
Loading

0 comments on commit 4b4724c

Please sign in to comment.