Skip to content

Commit ca1e543

Browse files
committed
test: update tests to reflect register flow chnages
1 parent 0e76205 commit ca1e543

3 files changed

Lines changed: 26 additions & 48 deletions

File tree

test/discovery/fixtures.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ export async function deployDiscoveryFixture() {
3939
.connect(owner)
4040
.grantRole(await collateralManagement.COLLATERAL_ADDER(), owner.address);
4141

42+
// Grant COLLATERAL_ADDER role to FlyoverDiscovery contract
43+
await collateralManagement
44+
.connect(owner)
45+
.grantRole(
46+
await collateralManagement.COLLATERAL_ADDER(),
47+
await discovery.getAddress()
48+
);
49+
4250
return {
4351
discovery,
4452
collateralManagement,
@@ -58,7 +66,7 @@ export async function deployDiscoveryWithProvidersFixture() {
5866
if (!pegInLp || !pegOutLp || !fullLp)
5967
throw new Error("LP can't be undefined");
6068

61-
// Register providers (Discovery enforces msg.value but does not move funds)
69+
// Register providers (Discovery now handles collateral addition automatically)
6270
await discovery
6371
.connect(pegInLp)
6472
.register("Pegin Provider", "lp1.com", true, ProviderType.PegIn, {
@@ -75,24 +83,6 @@ export async function deployDiscoveryWithProvidersFixture() {
7583
value: MIN_COLLATERAL * 2n,
7684
});
7785

78-
// Fund collateral management to reflect registration state
79-
await collateralManagement
80-
.connect(owner)
81-
.addPegInCollateralTo(pegInLp.address, { value: MIN_COLLATERAL });
82-
83-
await collateralManagement
84-
.connect(owner)
85-
.addPegOutCollateralTo(pegOutLp.address, { value: MIN_COLLATERAL });
86-
87-
const half = MIN_COLLATERAL;
88-
// For Both, split roughly half/half (rounding already exact as bigint)
89-
await collateralManagement
90-
.connect(owner)
91-
.addPegInCollateralTo(fullLp.address, { value: half });
92-
await collateralManagement
93-
.connect(owner)
94-
.addPegOutCollateralTo(fullLp.address, { value: half });
95-
9686
return {
9787
discovery,
9888
collateralManagement,

test/discovery/listing-filter.test.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,18 @@ describe("FlyoverDiscovery listing filters", () => {
2424
});
2525

2626
describe("FlyoverDiscovery listing edge cases", () => {
27-
it("does not list providers without sufficient collateral until collateral is added", async () => {
28-
const { discovery, collateralManagement, signers, owner, MIN_COLLATERAL } =
29-
await loadFixture(deployDiscoveryFixture);
27+
it("lists providers immediately after registration since collateral is added automatically", async () => {
28+
const { discovery, signers, MIN_COLLATERAL } = await loadFixture(
29+
deployDiscoveryFixture
30+
);
3031
const lp = signers.at(-1)!;
3132

3233
await discovery
3334
.connect(lp)
3435
.register("N", "U", true, ProviderType.PegIn, { value: MIN_COLLATERAL });
3536

36-
let providers = await discovery.getProviders();
37-
// Not listed because collateral management not yet funded for this LP
38-
expect(providers.length).to.equal(0);
39-
40-
await collateralManagement
41-
.connect(owner)
42-
.addPegInCollateralTo(lp.address, { value: MIN_COLLATERAL });
43-
44-
providers = await discovery.getProviders();
37+
const providers = await discovery.getProviders();
38+
// Provider is immediately listed because collateral is added automatically during registration
4539
expect(providers.length).to.equal(1);
4640
expect(providers[0].providerAddress).to.equal(lp.address);
4741
});

test/discovery/registration.test.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,30 +124,24 @@ describe("FlyoverDiscovery registration edge cases", () => {
124124
).to.be.revertedWithPanic(0x21);
125125
});
126126

127-
it("allows multiple registrations by the same EOA (separate ids)", async () => {
128-
const { discovery, collateralManagement, owner, signers, MIN_COLLATERAL } =
129-
await loadFixture(deployDiscoveryFixture);
127+
it("prevents multiple registrations by the same EOA", async () => {
128+
const { discovery, signers, MIN_COLLATERAL } = await loadFixture(
129+
deployDiscoveryFixture
130+
);
130131
const lp = signers.at(-1)!;
131132
await discovery.connect(lp).register("N1", "U1", true, ProviderType.PegIn, {
132133
value: MIN_COLLATERAL,
133134
});
134-
await discovery
135-
.connect(lp)
136-
.register("N2", "U2", true, ProviderType.PegOut, {
137-
value: MIN_COLLATERAL,
138-
});
139135

140-
// Fund both sides so both registrations are listable
141-
await collateralManagement
142-
.connect(owner)
143-
.addPegInCollateralTo(lp.address, { value: MIN_COLLATERAL });
144-
await collateralManagement
145-
.connect(owner)
146-
.addPegOutCollateralTo(lp.address, { value: MIN_COLLATERAL });
136+
// Second registration by the same EOA should fail
137+
await expect(
138+
discovery.connect(lp).register("N2", "U2", true, ProviderType.PegOut, {
139+
value: MIN_COLLATERAL,
140+
})
141+
).to.be.revertedWithCustomError(discovery, "AlreadyRegistered");
147142

148143
const providers = await discovery.getProviders();
149-
expect(providers.length).to.equal(2);
144+
expect(providers.length).to.equal(1);
150145
expect(providers[0].providerAddress).to.equal(lp.address);
151-
expect(providers[1].providerAddress).to.equal(lp.address);
152146
});
153147
});

0 commit comments

Comments
 (0)