Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: fix CI flaky tests #585

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e0ca4fb
test log
pedroferreira1 Oct 27, 2023
e1a8015
test: use yml config file for integration tests
pedroferreira1 Nov 1, 2023
3c05df3
tests: using yml env var in docker compose for integration tests
pedroferreira1 Nov 1, 2023
9370d92
tests: yml env var must be a path not a module
pedroferreira1 Nov 1, 2023
38f67e3
chore: reduce thresholds for testing
pedroferreira1 Nov 1, 2023
27da235
tests: await delegated authorities to arrive in destination wallet
pedroferreira1 Nov 1, 2023
88fbf1a
tests: we must await for all wallet2 delegate authorities
pedroferreira1 Nov 1, 2023
7aa8022
tests: await all funds injection from the receiving wallet
pedroferreira1 Nov 1, 2023
2f194f4
fix: cant use same variable name
pedroferreira1 Nov 1, 2023
46eadb6
fix: current address must be updated even if the tx used address is e…
pedroferreira1 Nov 1, 2023
76de557
chore: add node 18 and 20 to CI and remove unecessary delay
pedroferreira1 Nov 2, 2023
97600a3
chore: revert changes on workflow CI and integration thresholds
pedroferreira1 Nov 2, 2023
cabb56b
tests: always wait for tx received when injecting funds
pedroferreira1 Nov 2, 2023
d2f4dd8
fix: must have fund tx id
pedroferreira1 Nov 2, 2023
aa50b52
tests: refactor method to wait for tx received and update spent by of…
pedroferreira1 Nov 6, 2023
b13d8cb
feat: add processing status to new txs that arrive in the ws
pedroferreira1 Nov 6, 2023
561d93e
tests: process storage history after updating inputs spent by in tests
pedroferreira1 Nov 6, 2023
141079d
chore: remove console logs
pedroferreira1 Nov 6, 2023
6050676
tests: wait first block to release genesis reward before starting int…
pedroferreira1 Nov 6, 2023
4e52796
tests: decreasing 1% in functions for new wallet threshold
pedroferreira1 Nov 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions __tests__/integration/atomic_swap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('partial tx proposal', () => {
const hWallet2 = await generateWalletHelper();

// Injecting funds and creating a new custom token
const txI = await GenesisWalletHelper.injectFunds(await hWallet1.getAddressAtIndex(0), 103);
const txI = await GenesisWalletHelper.injectFunds(hWallet1, await hWallet1.getAddressAtIndex(0), 103);
const { hash: token1Uid } = await createTokenHelper(
hWallet1,
'Token1',
Expand All @@ -33,7 +33,7 @@ describe('partial tx proposal', () => {
);

// Injecting funds and creating a new custom token
await GenesisWalletHelper.injectFunds(await hWallet2.getAddressAtIndex(0), 10);
await GenesisWalletHelper.injectFunds(hWallet2, await hWallet2.getAddressAtIndex(0), 10);
const { hash: token2Uid } = await createTokenHelper(
hWallet2,
'Token2',
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('partial tx proposal', () => {
expect(tx.hash).toBeDefined();

await waitForTxReceived(hWallet1, tx.hash);
await delay(1000); // This transaction seems to take longer than usual to complete
await waitForTxReceived(hWallet2, tx.hash);

// Get the balance states before the exchange
const w1HTRAfter = await hWallet1.getBalance(HATHOR_TOKEN_CONFIG.uid);
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/configuration/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:
"--memory-storage",
]
environment:
HATHOR_CONFIG_FILE: privnet.conf.privnet
HATHOR_CONFIG_YAML: privnet/conf/privnet.yml
ports:
- "8083:8080"
- "40404:40404"
Expand Down
32 changes: 32 additions & 0 deletions __tests__/integration/configuration/privnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This file is the Private Network Configuration for the Fullnode
# It is consumed by the docker-compose.yml file on the integration folder.
# For more information, refer to:
# https://github.com/HathorNetwork/rfcs/blob/master/text/0033-private-network-guide.md

# This genesis adds the funds to the following wallet seed:
# avocado spot town typical traffic vault danger century property shallow divorce festival spend attack anchor afford rotate green audit adjust fade wagon depart level

P2PKH_VERSION_BYTE: x49
MULTISIG_VERSION_BYTE: x87
NETWORK_NAME: privatenet
BOOTSTRAP_DNS: []
ENABLE_PEER_WHITELIST: false

# Genesis stuff
GENESIS_OUTPUT_SCRIPT: 76a91466665b27f7dbc4c8c089d2f686c170c74d66f0b588ac
GENESIS_BLOCK_TIMESTAMP: 1643902665
GENESIS_BLOCK_NONCE: 4784939
GENESIS_BLOCK_HASH: 00000334a21fbb58b4db8d7ff282d018e03e2977abd3004cf378fb1d677c3967
GENESIS_TX1_NONCE: 0
GENESIS_TX1_HASH: 54165cef1fd4cf2240d702b8383c307c822c16ca407f78014bdefa189a7571c2
GENESIS_TX2_NONCE: 0
GENESIS_TX2_HASH: 039906854ce6309b3180945f2a23deb9edff369753f7082e19053f5ac11bfbae

MIN_TX_WEIGHT_K: 0
MIN_TX_WEIGHT_COEFFICIENT: 0
MIN_TX_WEIGHT: 1
REWARD_SPEND_MIN_BLOCKS: 1

CHECKPOINTS: []

extends: mainnet.yml
134 changes: 65 additions & 69 deletions __tests__/integration/hathorwallet_facade.test.js

Large diffs are not rendered by default.

36 changes: 22 additions & 14 deletions __tests__/integration/hathorwallet_others.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ describe('getAddressInfo', () => {
});

// Validating address after 1 transaction
await GenesisWalletHelper.injectFunds(addr0, 10);
await delay(500);
await GenesisWalletHelper.injectFunds(hWallet, addr0, 10);
await expect(hWallet.getAddressInfo(addr0)).resolves.toMatchObject({
total_amount_received: 10,
total_amount_sent: 0,
Expand Down Expand Up @@ -152,7 +151,7 @@ describe('getAddressInfo', () => {
const addr1Custom = await hWalletCustom.getAddressAtIndex(1);

// Creating custom token
await GenesisWalletHelper.injectFunds(addr0Custom, 1);
await GenesisWalletHelper.injectFunds(hWalletCustom, addr0Custom, 1);
const { hash: tokenUid } = await createTokenHelper(
hWalletCustom,
'getAddressInfo Token',
Expand Down Expand Up @@ -213,6 +212,7 @@ describe('getTxAddresses', () => {
changeAddress: WALLET_CONSTANTS.genesis.addresses[0]
});
await waitForTxReceived(hWallet, tx.hash);
await waitForTxReceived(gWallet, tx.hash);

// Validating the method results
const decodedTx = await hWallet.getTx(tx.hash);
Expand Down Expand Up @@ -269,7 +269,7 @@ describe('getAvailableUtxos', () => {
expect(utxoGenResult).toStrictEqual({ done: true, value: undefined });

// Inject a transaction and validate the results
const tx1 = await GenesisWalletHelper.injectFunds(await hWallet.getAddressAtIndex(0), 10);
const tx1 = await GenesisWalletHelper.injectFunds(hWallet, await hWallet.getAddressAtIndex(0), 10);

// Get correct results for a single transaction
utxoGenerator = await hWallet.getAvailableUtxos();
Expand Down Expand Up @@ -300,8 +300,8 @@ describe('getAvailableUtxos', () => {
* @type HathorWallet
*/
const hWallet = await generateWalletHelper();
const tx1 = await GenesisWalletHelper.injectFunds(await hWallet.getAddressAtIndex(0), 10);
const tx2 = await GenesisWalletHelper.injectFunds(await hWallet.getAddressAtIndex(1), 5);
const tx1 = await GenesisWalletHelper.injectFunds(hWallet, await hWallet.getAddressAtIndex(0), 10);
const tx2 = await GenesisWalletHelper.injectFunds(hWallet, await hWallet.getAddressAtIndex(1), 5);

// Validate that on the address that received tx1, the UTXO is listed
let utxoGenerator = await hWallet.getAvailableUtxos({ filter_address: await hWallet.getAddressAtIndex(0) });
Expand Down Expand Up @@ -331,7 +331,7 @@ describe('getAvailableUtxos', () => {
* @type HathorWallet
*/
const hWallet = await generateWalletHelper();
await GenesisWalletHelper.injectFunds(await hWallet.getAddressAtIndex(0), 10);
await GenesisWalletHelper.injectFunds(hWallet, await hWallet.getAddressAtIndex(0), 10);
const { hash: tokenUid } = await createTokenHelper(
hWallet,
'getAvailableUtxos Token',
Expand Down Expand Up @@ -420,7 +420,7 @@ describe('getUtxosForAmount', () => {
it('should work on a wallet containing a single tx', async () => {
const addr0 = await hWallet.getAddressAtIndex(0);
const addr1 = await hWallet.getAddressAtIndex(1);
const tx1 = await GenesisWalletHelper.injectFunds(addr0, 10);
const tx1 = await GenesisWalletHelper.injectFunds(hWallet, addr0, 10);
fundTx1hash = tx1.hash;

// No change amount
Expand Down Expand Up @@ -463,7 +463,7 @@ describe('getUtxosForAmount', () => {
it('should work on a wallet containing multiple txs', async () => {
const addr0 = await hWallet.getAddressAtIndex(0);
const addr1 = await hWallet.getAddressAtIndex(1);
const tx2 = await GenesisWalletHelper.injectFunds(addr1, 20);
const tx2 = await GenesisWalletHelper.injectFunds(hWallet, addr1, 20);

/*
* Since we don't know which order the transactions will be stored on the history,
Expand Down Expand Up @@ -572,8 +572,7 @@ describe('getUtxosForAmount', () => {
it('should not retrieve utxos marked as selected', async () => {
// Retrieving the utxo's data and marking it as selected
const addr = await hWallet.getAddressAtIndex(11);
await GenesisWalletHelper.injectFunds(addr, 100);
await delay(100);
await GenesisWalletHelper.injectFunds(hWallet, addr, 100);

const utxosAddr1 = await hWallet.getUtxos({ filter_address: addr });
const singleUtxoAddr1 = utxosAddr1.utxos[0];
Expand Down Expand Up @@ -601,7 +600,7 @@ describe('consolidateUtxos', () => {
beforeAll(async () => {
hWallet1 = await generateWalletHelper();
hWallet2 = await generateWalletHelper();
await GenesisWalletHelper.injectFunds(await hWallet2.getAddressAtIndex(0), 110);
await GenesisWalletHelper.injectFunds(hWallet2, await hWallet2.getAddressAtIndex(0), 110);
const { hash: tokenUid } = await createTokenHelper(
hWallet2,
'Consolidate Token',
Expand Down Expand Up @@ -635,6 +634,7 @@ describe('consolidateUtxos', () => {
{ token }
);
await waitForTxReceived(hWallet1, cleanTx.hash);
await waitForTxReceived(hWallet2, cleanTx.hash);
await waitUntilNextTimestamp(hWallet1, cleanTx.hash);
}

Expand All @@ -649,6 +649,7 @@ describe('consolidateUtxos', () => {
{ address: await hWallet1.getAddressAtIndex(1), value: 5, token: HATHOR_TOKEN_CONFIG.uid },
]);
await waitForTxReceived(hWallet1, fundTx.hash);
await waitForTxReceived(hWallet2, fundTx.hash);

await expect(hWallet1.consolidateUtxos(hWallet2.getAddressAtIndex(0)))
.rejects.toThrow('not owned by this wallet');
Expand All @@ -663,6 +664,7 @@ describe('consolidateUtxos', () => {
{ address: await hWallet1.getAddressAtIndex(1), value: 5, token: HATHOR_TOKEN_CONFIG.uid },
]);
await waitForTxReceived(hWallet1, fundTx.hash);
await waitForTxReceived(hWallet2, fundTx.hash);

// Sending transaction and validating the method response
const consolidateTx = await hWallet1.consolidateUtxos(
Expand Down Expand Up @@ -718,6 +720,7 @@ describe('consolidateUtxos', () => {
{ address: await hWallet1.getAddressAtIndex(4), value: 50, token: tokenHash },
]);
await waitForTxReceived(hWallet1, fundTx.hash);
await waitForTxReceived(hWallet2, fundTx.hash);

// Sending transaction and validating the method response
const consolidateTx = await hWallet1.consolidateUtxos(
Expand Down Expand Up @@ -779,6 +782,7 @@ describe('consolidateUtxos', () => {
{ address: addr2, value: 3, token: HATHOR_TOKEN_CONFIG.uid },
]);
await waitForTxReceived(hWallet1, fundTx.hash);
await waitForTxReceived(hWallet2, fundTx.hash);

// Sending transaction and validating the method response
const consolidateTx = await hWallet1.consolidateUtxos(
Expand Down Expand Up @@ -823,6 +827,7 @@ describe('consolidateUtxos', () => {
{ address: addr1, value: 5, token: HATHOR_TOKEN_CONFIG.uid },
]);
await waitForTxReceived(hWallet1, fundTx.hash);
await waitForTxReceived(hWallet2, fundTx.hash);

// Sending transaction and validating the method response
const consolidateTx = await hWallet1.consolidateUtxos(
Expand Down Expand Up @@ -861,6 +866,7 @@ describe('consolidateUtxos', () => {
{ address: addr2, value: 5, token: HATHOR_TOKEN_CONFIG.uid },
]);
await waitForTxReceived(hWallet1, fundTx.hash);
await waitForTxReceived(hWallet2, fundTx.hash);

// Sending transaction and validating the method response
const consolidateTx = await hWallet1.consolidateUtxos(
Expand Down Expand Up @@ -899,10 +905,11 @@ describe('consolidateUtxos', () => {
{ address: addr2, value: 40, token: HATHOR_TOKEN_CONFIG.uid },
]);
await waitForTxReceived(hWallet1, fundTx.hash);
await waitForTxReceived(hWallet2, fundTx.hash);

// Sending transaction and validating the method response
const consolidateTx = await hWallet1.consolidateUtxos(
await await hWallet1.getAddressAtIndex(4),
await hWallet1.getAddressAtIndex(4),
{
token: HATHOR_TOKEN_CONFIG.uid,
amount_bigger_than: 2,
Expand Down Expand Up @@ -940,6 +947,7 @@ describe('consolidateUtxos', () => {
{ address: await hWallet1.getAddressAtIndex(0), value: 1, token: tokenHash },
]);
await waitForTxReceived(hWallet1, fundTx.hash);
await waitForTxReceived(hWallet2, fundTx.hash);

// We should now have 4 utxos on wallet1 for this custom token
expect(await hWallet1.getUtxos({ token: tokenHash })).toHaveProperty('total_utxos_available', 4);
Expand Down Expand Up @@ -990,7 +998,7 @@ describe('getAuthorityUtxos', () => {

it('should find one authority utxo', async () => {
// Creating the token
await GenesisWalletHelper.injectFunds(await hWallet.getAddressAtIndex(0), 1);
await GenesisWalletHelper.injectFunds(hWallet, await hWallet.getAddressAtIndex(0), 1);
const { hash: tokenUid } = await createTokenHelper(
hWallet,
'getAuthorityUtxos Token',
Expand Down
9 changes: 6 additions & 3 deletions __tests__/integration/helpers/genesis-wallet.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class GenesisWalletHelper {

/**
* Internal method to send HTR to another wallet's address.
* @param {HathorWallet} destinationWallet Wallet object that we are sending the funds to
* @param {string} address
* @param {number} value
* @param [options]
Expand All @@ -65,7 +66,7 @@ export class GenesisWalletHelper {
* @returns {Promise<BaseTransactionResponse>}
* @private
*/
async _injectFunds(address, value, options = {}) {
async _injectFunds(destinationWallet, address, value, options = {}) {
try {
const result = await this.hWallet.sendTransaction(
address,
Expand All @@ -80,6 +81,7 @@ export class GenesisWalletHelper {
}

await waitForTxReceived(this.hWallet, result.hash, options.waitTimeout);
await waitForTxReceived(destinationWallet, result.hash, options.waitTimeout);
await waitUntilNextTimestamp(this.hWallet, result.hash);
return result;
} catch (e) {
Expand Down Expand Up @@ -107,16 +109,17 @@ export class GenesisWalletHelper {

/**
* An easy way to send HTR to another wallet's address for testing.
* @param {HathorWallet} destinationWallet Wallet object that we are sending the funds to
* @param {string} address
* @param {number} value
* @param [options]
* @param {number} [options.waitTimeout] Optional timeout for the websocket confirmation.
* Passing 0 here skips this waiting.
* @returns {Promise<BaseTransactionResponse>}
*/
static async injectFunds(address, value, options) {
static async injectFunds(destinationWallet, address, value, options) {
const instance = await GenesisWalletHelper.getSingleton();
return instance._injectFunds(address, value, options);
return instance._injectFunds(destinationWallet, address, value, options);
}

/**
Expand Down
Loading
Loading