Skip to content

Commit

Permalink
extend QiHDWallet scan unit test to 2 inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
alejoacosta74 authored and rileystephens28 committed Jan 21, 2025
1 parent 378f2d1 commit 84adb40
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 52 deletions.
106 changes: 54 additions & 52 deletions src/_tests/unit/qihdwallet-scan.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,67 +43,69 @@ describe('QiHDWallet scan', async function () {
const tests = loadTests<ScanTestCase>('qi-wallet-scan');

for (const test of tests) {
this.timeout(1200000);
describe(test.name, async function () {
this.timeout(1200000);

const mockProvider = new MockProvider();
const mockProvider = new MockProvider();

// set the provider outpoints
for (const outpoint of test.provider_outpoints) {
mockProvider.setOutpoints(outpoint.address, outpoint.outpoints);
}

// set the provider blocks
for (const block of test.provider_blocks) {
mockProvider.setBlock(block.key, block.block);
}
// set the provider outpoints
for (const outpoint of test.provider_outpoints) {
mockProvider.setOutpoints(outpoint.address, outpoint.outpoints);
}

// set the provider locked balace
for (const lockedBalance of test.provider_locked_balance) {
mockProvider.setLockedBalance(lockedBalance.address, BigInt(lockedBalance.balance));
}
// set the provider blocks
for (const block of test.provider_blocks) {
mockProvider.setBlock(block.key, block.block);
}

// set the provider balance
for (const balance of test.provider_balance) {
mockProvider.setBalance(balance.address, BigInt(balance.balance));
}
// set the provider locked balace
for (const lockedBalance of test.provider_locked_balance) {
mockProvider.setLockedBalance(lockedBalance.address, BigInt(lockedBalance.balance));
}

const mnemonic = Mnemonic.fromPhrase(test.mnemonic);
const wallet = QiHDWallet.fromMnemonic(mnemonic);
wallet.connect(mockProvider);
it('it scans the wallet with no errors', async function () {
try {
await wallet.scan(Zone.Cyprus1);
assert.ok(true, '====> TESTING: scan completed');
} catch (error) {
console.error('====> TESTING: error: ', error);
assert.fail('====> TESTING: error: ', error);
// set the provider balance
for (const balance of test.provider_balance) {
mockProvider.setBalance(balance.address, BigInt(balance.balance));
}
});
it('validates expected external addresses', async function () {
const externalAddresses = wallet.getAddressesForZone(Zone.Cyprus1);
const sortedExternalAddresses = externalAddresses.sort((a, b) => a.address.localeCompare(b.address));
const sortedExpectedExternalAddresses = test.expected_external_addresses.sort((a, b) =>
a.address.localeCompare(b.address),
);
assert.deepEqual(sortedExternalAddresses, sortedExpectedExternalAddresses);
});

it('validates expected change addresses', async function () {
const changeAddresses = wallet.getChangeAddressesForZone(Zone.Cyprus1);
const sortedChangeAddresses = changeAddresses.sort((a, b) => a.address.localeCompare(b.address));
const sortedExpectedChangeAddresses = test.expected_change_addresses.sort((a, b) =>
a.address.localeCompare(b.address),
);
assert.deepEqual(sortedChangeAddresses, sortedExpectedChangeAddresses);
});
const mnemonic = Mnemonic.fromPhrase(test.mnemonic);
const wallet = QiHDWallet.fromMnemonic(mnemonic);
wallet.connect(mockProvider);
it('it scans the wallet with no errors', async function () {
try {
await wallet.scan(Zone.Cyprus1);
assert.ok(true, '====> TESTING: scan completed');
} catch (error) {
console.error('====> TESTING: error: ', error);
assert.fail('====> TESTING: error: ', error);
}
});
it('validates expected external addresses', async function () {
const externalAddresses = wallet.getAddressesForZone(Zone.Cyprus1);
const sortedExternalAddresses = externalAddresses.sort((a, b) => a.address.localeCompare(b.address));
const sortedExpectedExternalAddresses = test.expected_external_addresses.sort((a, b) =>
a.address.localeCompare(b.address),
);
assert.deepEqual(sortedExternalAddresses, sortedExpectedExternalAddresses);
});

it('validates wallet balance', async function () {
const balance = await wallet.getBalanceForZone(Zone.Cyprus1);
assert.equal(balance.toString(), test.expected_balance.toString());
});
it('validates expected change addresses', async function () {
const changeAddresses = wallet.getChangeAddressesForZone(Zone.Cyprus1);
const sortedChangeAddresses = changeAddresses.sort((a, b) => a.address.localeCompare(b.address));
const sortedExpectedChangeAddresses = test.expected_change_addresses.sort((a, b) =>
a.address.localeCompare(b.address),
);
assert.deepEqual(sortedChangeAddresses, sortedExpectedChangeAddresses);
});

it('validates wallet balance', async function () {
const balance = await wallet.getBalanceForZone(Zone.Cyprus1);
assert.equal(balance.toString(), test.expected_balance.toString());
});

it('validates expected outpoints info', async function () {
assert.deepEqual(wallet.getOutpoints(Zone.Cyprus1), test.expected_outpoints_info);
it('validates expected outpoints info', async function () {
assert.deepEqual(wallet.getOutpoints(Zone.Cyprus1), test.expected_outpoints_info);
});
});
}
});
Binary file modified testcases/qi-wallet-scan.json.gz
Binary file not shown.

0 comments on commit 84adb40

Please sign in to comment.