diff --git a/.changeset/breezy-students-draw.md b/.changeset/breezy-students-draw.md new file mode 100644 index 00000000..f98dcba4 --- /dev/null +++ b/.changeset/breezy-students-draw.md @@ -0,0 +1,5 @@ +--- +"@fleet-sdk/mock-chain": minor +--- + +Add `MockChain.clearUTxOSet()` method. diff --git a/packages/mock-chain/src/mockChain.spec.ts b/packages/mock-chain/src/mockChain.spec.ts index f268b78a..fe2f66ae 100644 --- a/packages/mock-chain/src/mockChain.spec.ts +++ b/packages/mock-chain/src/mockChain.spec.ts @@ -46,6 +46,23 @@ describe("Mock chain instantiation", () => { expect(chain.parties[1]).to.be.equal(alice); }); + it("Should clear UTxO set", () => { + const chain = new MockChain(); + const bob = chain + .newParty() + .withBalance({ nanoergs: 1000000n }) + .withBalance({ nanoergs: 19827398237n }); + const alice = chain.newParty().withBalance({ nanoergs: 6000000n }); + + expect(bob.utxos).to.have.length(2); + expect(alice.utxos).to.have.length(1); + + chain.clearUTxOSet(); + + expect(bob.utxos).to.have.length(0); + expect(alice.utxos).to.have.length(0); + }); + it("Should simulate new blocks", () => { const blockTime = 120_000; const height = 100; diff --git a/packages/mock-chain/src/mockChain.ts b/packages/mock-chain/src/mockChain.ts index 3cbd8d45..b53f2e1f 100644 --- a/packages/mock-chain/src/mockChain.ts +++ b/packages/mock-chain/src/mockChain.ts @@ -77,6 +77,12 @@ export class MockChain { this.newBlocks(newHeight - this._height); } + clearUTxOSet() { + for (const party of this._parties) { + party.utxos.clear(); + } + } + newParty(name?: string): MockChainParty; newParty(params?: MockChainPartyParams): MockChainParty; newParty(nameOrParams?: string | MockChainPartyParams): MockChainParty { diff --git a/plugins/ageusd/src/exchangePlugin.spec.ts b/plugins/ageusd/src/exchangePlugin.spec.ts index 9a645862..e9d32905 100644 --- a/plugins/ageusd/src/exchangePlugin.spec.ts +++ b/plugins/ageusd/src/exchangePlugin.spec.ts @@ -29,9 +29,7 @@ describe("AgeUSD exchange plugin, reserve rate under 400%", () => { const implementor = chain.newParty("Implementor"); beforeEach(() => { - bob.utxos.clear(); - bankParty.utxos.clear(); - implementor.utxos.clear(); + chain.clearUTxOSet(); }); it("Should mint reserve coin with reserve at 348%", () => { @@ -415,9 +413,7 @@ describe("AgeUSD exchange plugin, reserve rate between 400% and 800%", () => { const implementor = chain.newParty("Implementor"); beforeEach(() => { - bob.utxos.clear(); - bankParty.utxos.clear(); - implementor.utxos.clear(); + chain.clearUTxOSet(); }); it("Should mint reserve coin with reserve at 437%", () => { @@ -924,9 +920,7 @@ describe("AgeUSD exchange plugin, reserve rate over 800%", () => { const implementor = chain.newParty("Implementor"); beforeEach(() => { - bob.utxos.clear(); - bankParty.utxos.clear(); - implementor.utxos.clear(); + chain.clearUTxOSet(); }); it("Should not mint reserve coin with reserve at 918%", () => {