Skip to content

Commit

Permalink
chore(tests): regression fix for master-b352814976 (#2149)
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?:

- [x] deps: ethers & hardhat installed for evm stuff
- [x] container: add `-ethrpcbind` to support eth rpc call + add
`RUST_LOG=debug`
- [x] CI
- [x] enhance `checkIfEvmTx`
- [x] fix: TD test (dftx composer, rpc & rawtx)
- [x] func: add `ListUnspentQueryOptions` to support provider
`listunspent` method
- [x] fix: UpdateMN test
- [x] lint: ts-ignore buggy AbortController.signal type check
  • Loading branch information
canonbrother authored Sep 25, 2023
1 parent db38bfa commit 1a2fcf4
Show file tree
Hide file tree
Showing 30 changed files with 7,775 additions and 215 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
cache: 'npm'

- run: npm ci
- run: npm run compile
- run: npm run all:build

test:
Expand All @@ -43,6 +44,7 @@ jobs:
cache: 'npm'

- run: npm ci
- run: npm run compile
- run: npm run ci:test
env:
GH_INSTANCE_INDEX: ${{ matrix.instance }}
Expand All @@ -64,6 +66,7 @@ jobs:
cache: 'npm'

- run: npm ci
- run: npm run compile
- run: npm run sanity

lint:
Expand All @@ -78,6 +81,7 @@ jobs:
cache: 'npm'

- run: npm ci
- run: npm run compile
- run: npx --no-install eslint .

docker-buildx:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
script: return require('./.github/scripts/release-ecr-tags.js')({ context })
result-encoding: string

- run: npm run compile
- run: npm run all:build
- run: npm run all:version ${{ steps.version.outputs.result }}

Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ tsconfig.build.tsbuildinfo
# Level
.level
.leveldb

# sol
artifacts
cache
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16-alpine3.13
FROM node:18-alpine3.18
ENV NODE_OPTIONS="--max-old-space-size=4096"

# Add curl to use docker healthcheck capability
Expand All @@ -18,8 +18,11 @@ COPY package-lock.json ./

COPY packages ./packages
COPY apps ./apps
COPY contracts ./
COPY hardhat.config.js ./

RUN npm ci
RUN npm run compile
RUN npm run build --workspace=apps

ARG APP
Expand Down
2 changes: 1 addition & 1 deletion apps/whale-api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.7"

services:
defi-blockchain:
image: defi/defichain:4.0.0-beta11
image: defi/defichain:master-b352814976
ports:
- "19554:19554"
command: >
Expand Down
10 changes: 3 additions & 7 deletions apps/whale-api/src/module.api/address.controller.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { NestFastifyApplication } from '@nestjs/platform-fastify'
import { createTestingApp, stopTestingApp, waitForAddressTxCount, waitForIndexedHeight } from '../e2e.module'
import { createSignedTxnHex, createToken, mintTokens, sendTokensToAddress } from '@defichain/testing'
import { WIF } from '@defichain/jellyfish-crypto'
import { RpcApiError } from '@defichain/jellyfish-api-core'
import { Testing } from '@defichain/jellyfish-testing'
import { ForbiddenException } from '@nestjs/common'
import BigNumber from 'bignumber.js'
Expand Down Expand Up @@ -1077,11 +1076,8 @@ describe('listTokens', () => {
expect(first.page?.next).toStrictEqual('2')
})

it('should throw error while listTokens with invalid address', async () => {
await expect(controller.listTokens('invalid', { size: 30 }))
.rejects.toThrow(RpcApiError)

await expect(controller.listTokens('invalid', { size: 30 }))
.rejects.toThrow('recipient (invalid) does not refer to any valid address')
it('should return empty and page undefined while listTokens with invalid address', async () => {
const tokens = await controller.listTokens('invalid', { size: 30 })
expect(tokens).toStrictEqual(expect.objectContaining({ data: [], page: undefined }))
})
})
10 changes: 3 additions & 7 deletions apps/whale-api/src/module.api/address.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { AddressController } from './address.controller'
import { createToken, mintTokens, sendTokensToAddress } from '@defichain/testing'
import { RpcApiError } from '@defichain/jellyfish-api-core'
import { Testing } from '@defichain/jellyfish-testing'
import BigNumber from 'bignumber.js'
import { createTestingApp, stopTestingApp } from '../e2e.module'
Expand Down Expand Up @@ -175,11 +174,8 @@ describe('listTokens', () => {
expect(first.page?.next).toStrictEqual('2')
})

it('should throw error while listTokens with invalid address', async () => {
await expect(controller.listTokens('invalid', { size: 30 }))
.rejects.toThrow(RpcApiError)

await expect(controller.listTokens('invalid', { size: 30 }))
.rejects.toThrow('recipient (invalid) does not refer to any valid address')
it('should return empty and page undefined while listTokens with invalid address', async () => {
const tokens = await controller.listTokens('invalid', { size: 30 })
expect(tokens).toStrictEqual(expect.objectContaining({ data: [], page: undefined }))
})
})
6 changes: 5 additions & 1 deletion apps/whale-api/src/module.indexer/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { blockchain } from '@defichain/jellyfish-api-core'

function checkIfEvmTx (txn: blockchain.Transaction): boolean {
// To identify that the transaction is evmtx, it has to have exactly 2 null transaction ids
return txn.vin.length === 2 && txn.vin.every(vin => vin.txid === '0000000000000000000000000000000000000000000000000000000000000000')
return txn.vin.length === 2 &&
txn.vin.every(vin => vin.txid === '0000000000000000000000000000000000000000000000000000000000000000') &&
txn.vout.length === 1 &&
txn.vout[0].scriptPubKey.asm.startsWith('OP_RETURN 4466547839') &&
txn.vout[0].value.isEqualTo(0)
}

export {
Expand Down
76 changes: 76 additions & 0 deletions contracts/TransferDomain.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// File: @openzeppelin/[email protected]/token/ERC20/IERC20.sol

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

pragma solidity ^0.8.0;

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

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.2 <0.9.0;

/**
* @title TransferDomain
*/
contract TransferDomain {
event Transfer(address indexed from, address indexed to, uint256 amount);
event NativeAddress(string nativeAddress);

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

emit Transfer(from, to, amount);
emit NativeAddress(nativeAddress);
}

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

/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual 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 returns (uint8) {
return 18;
}

function bridgeDST20(
address contractAddress,
address from,
address payable to,
uint256 amount,
string memory nativeAddress
) external {
if (to != address(this)) {
IERC20(contractAddress).transferFrom(from, to, amount);
}
emit NativeAddress(nativeAddress);
}
}
4 changes: 4 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: '0.8.19'
}
Loading

0 comments on commit 1a2fcf4

Please sign in to comment.