Skip to content

Commit

Permalink
Remove usage of MINIMUM_PEGIN_VALUE_IN_BTC constant in 01_03_05-2wp_m…
Browse files Browse the repository at this point in the history
…ultisig_not_compatible
  • Loading branch information
marcos-iov committed Sep 19, 2023
1 parent 6f97188 commit e6397b5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
8 changes: 4 additions & 4 deletions tests/01_03_04-2wp_segwit_not_compatible.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ describe('Lock p2sh-p2wpkh address', () => {
});

it('lock should fail when using p2sh-p2wpkh address', async () => {
const latestActiveForkName = await getLatestActiveForkName();
const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName);

const minimumPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call();
const minimumPeginValueInBtc = satoshisToBtc(minimumPeginValueInSatoshis);
const senderAddress = await btcTxHelper.generateBtcAddress('p2sh-segwit')

const latestActiveForkName = await getLatestActiveForkName();
const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName);
const federationAddress = await bridge.methods.getFederationAddress().call();

const federationAddressBalanceInitial = Number(await btcTxHelper.getAddressBalance(federationAddress));

const senderAddress = await btcTxHelper.generateBtcAddress('p2sh-segwit')
await btcTxHelper.fundAddress(senderAddress.address, minimumPeginValueInBtc + btcTxHelper.getFee());

const btcPeginTxHash = await sendPegin(rskTxHelper, btcTxHelper, senderAddress, minimumPeginValueInBtc);
Expand Down
26 changes: 14 additions & 12 deletions tests/01_03_05-2wp_multisig_not_compatible.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const expect = require('chai').expect
const { satoshisToBtc } = require('btc-eth-unit-converter');
const rskUtils = require('../lib/rsk-utils');
const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider');

const { getBtcClient } = require('../lib/btc-client-provider');
const { sendPegin, MINIMUM_PEGIN_VALUE_IN_BTC } = require('../lib/2wp-utils');
const { sendPegin } = require('../lib/2wp-utils');
const { getBridge, getLatestActiveForkName } = require('../lib/precompiled-abi-forks-util');
const { isUtxoRegisteredInBridge } = require('../lib/2wp-utils');

Expand All @@ -15,7 +15,7 @@ const fulfillRequirementsToRunAsSingleTestFile = async () => {
await rskUtils.activateFork(Runners.common.forks.wasabi100);
};

describe('Lock multisig address', () => {
describe('Peg-in multisig address', () => {
before(async () => {
rskTxHelpers = getRskTransactionHelpers();
rskTxHelper = rskTxHelpers[0];
Expand All @@ -27,30 +27,32 @@ describe('Lock multisig address', () => {
});

// Should fail and not refund when sending a pengin from a multisig address pre papyrus
it('lock should fail when using multisig address', async () => {
const senderAddress = await btcTxHelper.generateMultisigAddress(3, 2, 'legacy');

it('Peg-in should fail when using multisig address', async () => {
const latestActiveForkName = await getLatestActiveForkName();
const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName);
const federationAddress = await bridge.methods.getFederationAddress().call();

const minimumPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call();
const minimumPeginValueInBtc = satoshisToBtc(minimumPeginValueInSatoshis);

const federationAddress = await bridge.methods.getFederationAddress().call();
const federationAddressBalanceInitial = Number(await btcTxHelper.getAddressBalance(federationAddress));

await btcTxHelper.fundAddress(senderAddress.address, MINIMUM_PEGIN_VALUE_IN_BTC + btcTxHelper.getFee());
const senderAddress = await btcTxHelper.generateMultisigAddress(3, 2, 'legacy');
await btcTxHelper.fundAddress(senderAddress.address, minimumPeginValueInBtc + btcTxHelper.getFee());

const btcPeginTxHash = await sendPegin(rskTxHelper, btcTxHelper, senderAddress, MINIMUM_PEGIN_VALUE_IN_BTC);
const btcPeginTxHash = await sendPegin(rskTxHelper, btcTxHelper, senderAddress, minimumPeginValueInBtc);

const federationAddressBalanceAfterPegin = Number(await btcTxHelper.getAddressBalance(federationAddress));
expect(Number(federationAddressBalanceAfterPegin)).to.be.equal(Number(federationAddressBalanceInitial + MINIMUM_PEGIN_VALUE_IN_BTC));
expect(Number(federationAddressBalanceAfterPegin)).to.be.equal(Number(federationAddressBalanceInitial + minimumPeginValueInBtc));

const isPeginUtxoRegistered = await isUtxoRegisteredInBridge(rskTxHelper, btcPeginTxHash);
expect(isPeginUtxoRegistered).to.be.false;

const federationAddressBalanceFinal = Number(await btcTxHelper.getAddressBalance(federationAddress));
expect(Number(federationAddressBalanceFinal)).to.be.equal(Number(federationAddressBalanceInitial + MINIMUM_PEGIN_VALUE_IN_BTC));
expect(Number(federationAddressBalanceFinal)).to.be.equal(Number(federationAddressBalanceInitial + minimumPeginValueInBtc));

const senderAddressBalanceFinal = await btcTxHelper.getAddressBalance(senderAddress.address);
expect(Number(senderAddressBalanceFinal)).to.be.equal(0);
})
});
});

7 changes: 3 additions & 4 deletions tests/02_00_03-2wp_multisig_compatible.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ describe('Lock multisig address', () => {
it('lock should work when using multisig address', async () => {
const latestActiveForkName = await getLatestActiveForkName();
const bridge = getBridge(rskTxHelper.getClient(), latestActiveForkName);
const federationAddress = await bridge.methods.getFederationAddress().call();

const minimumPeginValueInSatoshis = await bridge.methods.getMinimumLockTxValue().call();
const minimumPeginValueInBtc = satoshisToBtc(minimumPeginValueInSatoshis);

const senderAddressInfo = await btcTxHelper.generateMultisigAddress(3, 2, 'legacy');

const federationAddress = await bridge.methods.getFederationAddress().call();
const federationAddressBalanceInitial = Number(await btcTxHelper.getAddressBalance(federationAddress));


const senderAddressInfo = await btcTxHelper.generateMultisigAddress(3, 2, 'legacy');
await btcTxHelper.fundAddress(senderAddressInfo.address, minimumPeginValueInBtc + btcTxHelper.getFee());
await sendPegin(rskTxHelper, btcTxHelper, senderAddressInfo, minimumPeginValueInBtc);

Expand Down

0 comments on commit e6397b5

Please sign in to comment.