diff --git a/lib/wallet/migrations.js b/lib/wallet/migrations.js index 2cab9e43e..9b49bd4c9 100644 --- a/lib/wallet/migrations.js +++ b/lib/wallet/migrations.js @@ -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; @@ -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(); @@ -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; diff --git a/test/data/migrations/wallet-4-bid-reveal-gen.js b/test/data/migrations/wallet-4-bid-reveal-gen.js index 05be7053e..b42934dfe 100644 --- a/test/data/migrations/wallet-4-bid-reveal-gen.js +++ b/test/data/migrations/wallet-4-bid-reveal-gen.js @@ -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), [ diff --git a/test/wallet-test.js b/test/wallet-test.js index 4bc1cbc26..f9ebd56b2 100644 --- a/test/wallet-test.js +++ b/test/wallet-test.js @@ -3649,7 +3649,7 @@ describe('Wallet', function() { } }; - const NAME = 'testname'; + const NAME = rules.grindName(10, 1, network); const NAMEHASH = rules.hashString(NAME); let wallet; @@ -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 () => {