Skip to content

Commit

Permalink
test: fix wallet test case for bidreveal.
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Aug 28, 2024
1 parent 3ae2296 commit fd2e57a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 6 additions & 0 deletions lib/wallet/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,10 @@ class MigrateBidRevealEntries extends AbstractMigration {
const totalOld = nameLen + 1 + 13;
const totalNew = nameLen + 1 + 13 + 36;

// allow migration to be interrupted in the middle.
assert(value.length === totalOld || value.length === totalNew);

// skip if already migrated.
if (value.length === totalNew)
continue;

Expand All @@ -591,11 +593,14 @@ class MigrateBidRevealEntries extends AbstractMigration {
const bidKey = txlayout.i.encode(
nameHash, bidPrevout.hash, bidPrevout.index);
const bidRecord = await bucket.get(bidKey);
// ensure bid exists.
assert(bidRecord);

const newReveal = Buffer.concat([value, bidPrevout.encode()]);
assert(newReveal.length === totalNew);
// update reveal with bid outpoint.
b.put(key, newReveal);
// index bid to reveal.
b.put(txlayout.E.encode(nameHash, bidPrevout.hash, bidPrevout.index),
(new Outpoint(txHash, txIndex)).encode());
await b.write();
Expand Down Expand Up @@ -648,6 +653,7 @@ class MigrateBidRevealEntries extends AbstractMigration {
const nameLen = value[0];
const totalNew = nameLen + 1 + 41 + 4;

// allow migration to be interrupted in the middle.
if (totalNew === value.length)
continue;

Expand Down
6 changes: 3 additions & 3 deletions test/data/migrations/wallet-4-bid-reveal-gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ let timeCounter = 0;

// fund wallets
const mtx1 = new MTX();
mtx1.addInput(wutils.determinsticInput(txID++));
mtx1.addInput(wutils.deterministicInput(txID++));
mtx1.addOutput(await wallet1.receiveAddress(0), 10e6);

const mtx2 = new MTX();
mtx2.addInput(wutils.determinsticInput(txID++));
mtx2.addInput(wutils.deterministicInput(txID++));
mtx2.addOutput(await wallet1.receiveAddress(1), 10e6);

// fund second wallet.
const mtx3 = new MTX();
mtx3.addInput(wutils.determinsticInput(txID++));
mtx3.addInput(wutils.deterministicInput(txID++));
mtx3.addOutput(await wallet2.receiveAddress(), 10e6);

await wdb.addBlock(wutils.nextEntry(wdb), [
Expand Down
6 changes: 1 addition & 5 deletions test/wallet-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3649,7 +3649,7 @@ describe('Wallet', function() {
}
};

const NAME = 'testname';
const NAME = rules.grindName(10, 1, network);
const NAMEHASH = rules.hashString(NAME);
let wallet;

Expand All @@ -3664,10 +3664,6 @@ describe('Wallet', function() {
await wdb.connect();

wallet = await wdb.create();

// rollout all names
wdb.height = 52 * 144 * 7;
wdb.state.height = 52 * 144 * 7;
});

after(async () => {
Expand Down

0 comments on commit fd2e57a

Please sign in to comment.