Skip to content

Commit

Permalink
Removes old basic pegout tests already covered by new test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-then committed Oct 24, 2024
1 parent 8c226f4 commit 70af72b
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 294 deletions.
81 changes: 1 addition & 80 deletions lib/tests/2wp-legacy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const expect = require('chai').expect
const { ensure0x, removePrefix0x} = require('../utils');
const { ensure0x} = require('../utils');
const whitelistingAssertions = require('../assertions/whitelisting');
const rskUtils = require('../rsk-utils');
const CustomError = require('../CustomError');
Expand All @@ -10,8 +10,6 @@ const { getDerivedRSKAddressInformation } = require('@rsksmart/btc-rsk-derivatio
const btcEthUnitConverter = require('@rsksmart/btc-eth-unit-converter');
const { sendTxToBridge, donateToBridge } = require('../2wp-utils');
const { waitAndUpdateBridge } = require('../rsk-utils');
const { decodeOutpointValues, encodeOutpointValuesAsMap } = require("../varint");
const {getBridgeState} = require("@rsksmart/bridge-state-data-parser");
const {PEGOUT_EVENTS} = require("../constants");

const DONATION_AMOUNT = 250;
Expand All @@ -23,18 +21,6 @@ let rskTxHelpers;
let federationAddress;
let minimumPeginValueInBtc;

const assertPegoutTransactionCreatedEventIsEmitted = async (localRskTxHelper, activeFederationUtxosBeforePegout) => {
const pegoutTransactionCreatedEvent = await rskUtils.findEventInBlock(localRskTxHelper, PEGOUT_EVENTS.PEGOUT_TRANSACTION_CREATED.name);
expect(pegoutTransactionCreatedEvent).to.not.be.null;
const encodedUtxoOutpointValues = Buffer.from(removePrefix0x(pegoutTransactionCreatedEvent.arguments.utxoOutpointValues), 'hex');

const federationUtxoValues = encodeOutpointValuesAsMap(activeFederationUtxosBeforePegout);

const outpointValues = decodeOutpointValues(encodedUtxoOutpointValues);

expect(outpointValues.every(value => value in federationUtxoValues)).to.be.true;
}

const execute = (description, getRskHost) => {

describe(description, () => {
Expand Down Expand Up @@ -69,71 +55,6 @@ const execute = (description, getRskHost) => {
return federationAddress;
});

it('should transfer RBTC to BTC - Above minimum pegout value', async () => {

const INITIAL_RSK_BALANCE = 1;
const PEGOUT_VALUE_IN_RBTC = 0.5;
const MAX_EXPECTED_FEE = 0.001;
const pegoutValueInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(PEGOUT_VALUE_IN_RBTC));
const maxExpectedFeeInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(MAX_EXPECTED_FEE));

const initialFederationBalanceInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(await btcTxHelper.getAddressBalance(federationAddress)));

const btcAddressInformation = await btcTxHelper.generateBtcAddress('legacy');

const recipientRskAddressInfo = getDerivedRSKAddressInformation(btcAddressInformation.privateKey, btcTxHelper.btcConfig.network);

await rskTxHelper.importAccount(recipientRskAddressInfo.privateKey);
const unlocked = await rskTxHelper.unlockAccount(recipientRskAddressInfo.address);
expect(unlocked, 'Account was not unlocked').to.be.true;

await rskUtils.sendFromCow(rskTxHelper, recipientRskAddressInfo.address, Number(btcEthUnitConverter.btcToWeis(INITIAL_RSK_BALANCE)));

const bridgeStateBeforePegout = await getBridgeState(rskTxHelper.getClient());
const activeFederationUtxosBeforePegout = bridgeStateBeforePegout.activeFederationUtxos;
const pegoutTransaction = await sendTxToBridge(rskTxHelper, PEGOUT_VALUE_IN_RBTC, recipientRskAddressInfo.address);

const pegoutRequestReceivedEvent = await rskUtils.findEventInBlock(rskTxHelper, PEGOUT_EVENTS.RELEASE_REQUEST_RECEIVED.name);
expect(pegoutRequestReceivedEvent).to.not.be.null;
const btcDestinationAddress = pegoutRequestReceivedEvent.arguments.btcDestinationAddress;
expect(pegoutRequestReceivedEvent.arguments.sender.toLowerCase()).to.equal(ensure0x(recipientRskAddressInfo.address));
expect(Number(pegoutRequestReceivedEvent.arguments.amount)).to.equal(pegoutValueInSatoshis);
expect(btcAddressInformation.address).to.equal(btcDestinationAddress);

const pegoutCreatedValidations = async (localRskTxHelper) => {

const pegoutRequestedEvent = await rskUtils.findEventInBlock(localRskTxHelper, PEGOUT_EVENTS.RELEASE_REQUESTED.name);
expect(pegoutRequestedEvent).to.not.be.null;
expect(Number(pegoutRequestedEvent.arguments.amount)).to.equal(pegoutValueInSatoshis);

const batchPegoutCreatedEvent = await rskUtils.findEventInBlock(localRskTxHelper, PEGOUT_EVENTS.BATCH_PEGOUT_CREATED.name);
expect(batchPegoutCreatedEvent).to.not.be.null;
expect(batchPegoutCreatedEvent.arguments.releaseRskTxHashes.includes(pegoutTransaction.transactionHash)).to.be.true;

// TODO: Uncomment this line when lovell700 is active.
// await assertPegoutTransactionCreatedEventIsEmitted(localRskTxHelper, activeFederationUtxosBeforePegout);

};

const pegoutConfirmedValidations = async (localRskTxHelper) => {
const pegoutConfirmedEvent = await rskUtils.findEventInBlock(localRskTxHelper, PEGOUT_EVENTS.PEGOUT_CONFIRMED.name);
expect(pegoutConfirmedEvent).to.not.be.null;
};

const callbacks = {
pegoutCreatedCallback: pegoutCreatedValidations,
pegoutConfirmedCallback: pegoutConfirmedValidations,
};

await rskUtils.triggerRelease(rskTxHelpers, btcTxHelper, callbacks);
const finalFederationBalanceInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(await btcTxHelper.getAddressBalance(federationAddress)));
const finalDestinationAddressBalanceInSatoshis = Number(btcEthUnitConverter.btcToSatoshis(await btcTxHelper.getAddressBalance(btcAddressInformation.address)));
const difference = pegoutValueInSatoshis - finalDestinationAddressBalanceInSatoshis;
expect(difference).to.be.at.most(maxExpectedFeeInSatoshis);
expect(finalFederationBalanceInSatoshis).to.equal(initialFederationBalanceInSatoshis - pegoutValueInSatoshis);

});

it('should transfer RBTC to BTC - Below minimum pegout value', async() => {
try {
const INITIAL_RSK_BALANCE = 2;
Expand Down
72 changes: 0 additions & 72 deletions tests/01_03_06-2wp_no_locking_cap.js

This file was deleted.

62 changes: 0 additions & 62 deletions tests/01_06_02-pre-fingerroot500-release_request_received_bytes.js

This file was deleted.

80 changes: 0 additions & 80 deletions tests/02_00_06-2wp-new-minimum.js

This file was deleted.

0 comments on commit 70af72b

Please sign in to comment.