Skip to content

Commit

Permalink
mock-chain: add MockChain.clearUTxOSet() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
arobsn committed Jul 21, 2023
1 parent 3b6d3aa commit c07d23b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-students-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fleet-sdk/mock-chain": minor
---

Add `MockChain.clearUTxOSet()` method.
17 changes: 17 additions & 0 deletions packages/mock-chain/src/mockChain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions packages/mock-chain/src/mockChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 3 additions & 9 deletions plugins/ageusd/src/exchangePlugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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%", () => {
Expand Down Expand Up @@ -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%", () => {
Expand Down Expand Up @@ -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%", () => {
Expand Down

0 comments on commit c07d23b

Please sign in to comment.