Skip to content

Commit 1a2fcf4

Browse files
authored
chore(tests): regression fix for master-b352814976 (#2149)
<!-- 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
1 parent db38bfa commit 1a2fcf4

File tree

30 files changed

+7775
-215
lines changed

30 files changed

+7775
-215
lines changed

.github/workflows/ci.yml

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
cache: 'npm'
2424

2525
- run: npm ci
26+
- run: npm run compile
2627
- run: npm run all:build
2728

2829
test:
@@ -43,6 +44,7 @@ jobs:
4344
cache: 'npm'
4445

4546
- run: npm ci
47+
- run: npm run compile
4648
- run: npm run ci:test
4749
env:
4850
GH_INSTANCE_INDEX: ${{ matrix.instance }}
@@ -64,6 +66,7 @@ jobs:
6466
cache: 'npm'
6567

6668
- run: npm ci
69+
- run: npm run compile
6770
- run: npm run sanity
6871

6972
lint:
@@ -78,6 +81,7 @@ jobs:
7881
cache: 'npm'
7982

8083
- run: npm ci
84+
- run: npm run compile
8185
- run: npx --no-install eslint .
8286

8387
docker-buildx:

.github/workflows/release-publish.yml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
script: return require('./.github/scripts/release-ecr-tags.js')({ context })
2626
result-encoding: string
2727

28+
- run: npm run compile
2829
- run: npm run all:build
2930
- run: npm run all:version ${{ steps.version.outputs.result }}
3031

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ tsconfig.build.tsbuildinfo
4444
# Level
4545
.level
4646
.leveldb
47+
48+
# sol
49+
artifacts
50+
cache

Dockerfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:16-alpine3.13
1+
FROM node:18-alpine3.18
22
ENV NODE_OPTIONS="--max-old-space-size=4096"
33

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

1919
COPY packages ./packages
2020
COPY apps ./apps
21+
COPY contracts ./
22+
COPY hardhat.config.js ./
2123

2224
RUN npm ci
25+
RUN npm run compile
2326
RUN npm run build --workspace=apps
2427

2528
ARG APP

apps/whale-api/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: "3.7"
22

33
services:
44
defi-blockchain:
5-
image: defi/defichain:4.0.0-beta11
5+
image: defi/defichain:master-b352814976
66
ports:
77
- "19554:19554"
88
command: >

apps/whale-api/src/module.api/address.controller.e2e.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { NestFastifyApplication } from '@nestjs/platform-fastify'
44
import { createTestingApp, stopTestingApp, waitForAddressTxCount, waitForIndexedHeight } from '../e2e.module'
55
import { createSignedTxnHex, createToken, mintTokens, sendTokensToAddress } from '@defichain/testing'
66
import { WIF } from '@defichain/jellyfish-crypto'
7-
import { RpcApiError } from '@defichain/jellyfish-api-core'
87
import { Testing } from '@defichain/jellyfish-testing'
98
import { ForbiddenException } from '@nestjs/common'
109
import BigNumber from 'bignumber.js'
@@ -1077,11 +1076,8 @@ describe('listTokens', () => {
10771076
expect(first.page?.next).toStrictEqual('2')
10781077
})
10791078

1080-
it('should throw error while listTokens with invalid address', async () => {
1081-
await expect(controller.listTokens('invalid', { size: 30 }))
1082-
.rejects.toThrow(RpcApiError)
1083-
1084-
await expect(controller.listTokens('invalid', { size: 30 }))
1085-
.rejects.toThrow('recipient (invalid) does not refer to any valid address')
1079+
it('should return empty and page undefined while listTokens with invalid address', async () => {
1080+
const tokens = await controller.listTokens('invalid', { size: 30 })
1081+
expect(tokens).toStrictEqual(expect.objectContaining({ data: [], page: undefined }))
10861082
})
10871083
})

apps/whale-api/src/module.api/address.controller.spec.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
22
import { AddressController } from './address.controller'
33
import { createToken, mintTokens, sendTokensToAddress } from '@defichain/testing'
4-
import { RpcApiError } from '@defichain/jellyfish-api-core'
54
import { Testing } from '@defichain/jellyfish-testing'
65
import BigNumber from 'bignumber.js'
76
import { createTestingApp, stopTestingApp } from '../e2e.module'
@@ -175,11 +174,8 @@ describe('listTokens', () => {
175174
expect(first.page?.next).toStrictEqual('2')
176175
})
177176

178-
it('should throw error while listTokens with invalid address', async () => {
179-
await expect(controller.listTokens('invalid', { size: 30 }))
180-
.rejects.toThrow(RpcApiError)
181-
182-
await expect(controller.listTokens('invalid', { size: 30 }))
183-
.rejects.toThrow('recipient (invalid) does not refer to any valid address')
177+
it('should return empty and page undefined while listTokens with invalid address', async () => {
178+
const tokens = await controller.listTokens('invalid', { size: 30 })
179+
expect(tokens).toStrictEqual(expect.objectContaining({ data: [], page: undefined }))
184180
})
185181
})

apps/whale-api/src/module.indexer/helper.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { blockchain } from '@defichain/jellyfish-api-core'
22

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

812
export {

contracts/TransferDomain.sol

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// File: @openzeppelin/[email protected]/token/ERC20/IERC20.sol
2+
3+
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
4+
5+
pragma solidity ^0.8.0;
6+
7+
interface IERC20 {
8+
function transferFrom(address from, address to, uint256 amount) external returns (bool);
9+
}
10+
11+
// SPDX-License-Identifier: MIT
12+
13+
pragma solidity >=0.8.2 <0.9.0;
14+
15+
/**
16+
* @title TransferDomain
17+
*/
18+
contract TransferDomain {
19+
event Transfer(address indexed from, address indexed to, uint256 amount);
20+
event NativeAddress(string nativeAddress);
21+
22+
function transfer(address from, address payable to, uint256 amount, string memory nativeAddress) external {
23+
if (to != address(this)) {
24+
require(address(this).balance >= amount, "Insufficient contract balance");
25+
to.transfer(amount);
26+
}
27+
28+
emit Transfer(from, to, amount);
29+
emit NativeAddress(nativeAddress);
30+
}
31+
32+
/**
33+
* @dev Returns the name of the token.
34+
*/
35+
function name() public view virtual returns (string memory) {
36+
return "DFI";
37+
}
38+
39+
/**
40+
* @dev Returns the symbol of the token, usually a shorter version of the
41+
* name.
42+
*/
43+
function symbol() public view virtual returns (string memory) {
44+
return "DFI";
45+
}
46+
47+
/**
48+
* @dev Returns the number of decimals used to get its user representation.
49+
* For example, if `decimals` equals `2`, a balance of `505` tokens should
50+
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
51+
*
52+
* Tokens usually opt for a value of 18, imitating the relationship between
53+
* Ether and Wei. This is the default value returned by this function, unless
54+
* it's overridden.
55+
*
56+
* NOTE: This information is only used for _display_ purposes: it in
57+
* no way affects any of the arithmetic of the contract, including
58+
* {IERC20-balanceOf} and {IERC20-transfer}.
59+
*/
60+
function decimals() public view virtual returns (uint8) {
61+
return 18;
62+
}
63+
64+
function bridgeDST20(
65+
address contractAddress,
66+
address from,
67+
address payable to,
68+
uint256 amount,
69+
string memory nativeAddress
70+
) external {
71+
if (to != address(this)) {
72+
IERC20(contractAddress).transferFrom(from, to, amount);
73+
}
74+
emit NativeAddress(nativeAddress);
75+
}
76+
}

hardhat.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** @type import('hardhat/config').HardhatUserConfig */
2+
module.exports = {
3+
solidity: '0.8.19'
4+
}

0 commit comments

Comments
 (0)