Skip to content

Commit 6e915dd

Browse files
committed
fix test
1 parent c38746c commit 6e915dd

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

contract-tests/src/subtensor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ export async function resetNetworkLastLock(api: TypedApi<typeof devnet>) {
413413
const valueCodec = codec.query.SubtensorModule.NetworkLastLockCost.value
414414

415415
// Encode the value 1 TAO as SCALE-encoded bytes
416-
const encodedValue = valueCodec.enc(BigInt(10000000000))
416+
const encodedValue = valueCodec.enc(BigInt(0))
417417

418418
const changes: [Binary, Binary][] = [[Binary.fromHex(key.toString()), Binary.fromBytes(encodedValue)]];
419419
const internalCall = api.tx.System.set_storage({ items: changes })

contract-tests/test/leasing.precompile.test.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ describe("Test Leasing precompile", () => {
2424
let leaseContract: ethers.Contract;
2525
let crowdloanContract: ethers.Contract;
2626
let neuronContract: ethers.Contract;
27+
const crowdloanDeposit = BigInt(100_000_000_000);
28+
let crowdloanCap: bigint;
2729

2830
const alice = getAliceSigner();
2931
const bob = getBobSigner();
@@ -42,12 +44,17 @@ describe("Test Leasing precompile", () => {
4244
await forceSetBalanceToEthAddress(api, wallet2.address);
4345

4446
await resetNetworkLastLock(api);
47+
const minLockCost = await api.query.SubtensorModule.NetworkMinLockCost.getValue();
48+
// guarantee that the crowdloan cap is larger than the deposit
49+
if (minLockCost > crowdloanDeposit) {
50+
crowdloanCap = minLockCost * BigInt(2);
51+
} else {
52+
crowdloanCap = crowdloanDeposit * BigInt(2);
53+
}
4554
});
4655

4756
it("gets an existing lease created on substrate side, its subnet id and its contributor shares", async () => {
4857
const nextCrowdloanId = await api.query.Crowdloan.NextCrowdloanId.getValue();
49-
const crowdloanDeposit = BigInt(100_000_000_000); // 100 TAO
50-
const crowdloanCap = await api.query.SubtensorModule.NetworkLastLockCost.getValue() * BigInt(10);
5158
const crowdloanEnd = await api.query.System.Number.getValue() + 100;
5259
const leaseEmissionsShare = 15;
5360
const leaseEnd = await api.query.System.Number.getValue() + 300;
@@ -69,8 +76,8 @@ describe("Test Leasing precompile", () => {
6976
amount: crowdloanCap - crowdloanDeposit,
7077
}).signAndSubmit(bob);
7178

72-
await waitForFinalizedBlock(api, crowdloanEnd);
7379

80+
await waitForFinalizedBlock(api, crowdloanEnd);
7481
const nextLeaseId = await api.query.SubtensorModule.NextSubnetLeaseId.getValue();
7582
await api.tx.Crowdloan.finalize({ crowdloan_id: nextCrowdloanId }).signAndSubmit(alice);
7683

@@ -100,9 +107,7 @@ describe("Test Leasing precompile", () => {
100107

101108
it("registers a new leased network through a crowdloan and retrieves the lease", async () => {
102109
const nextCrowdloanId = await api.query.Crowdloan.NextCrowdloanId.getValue();
103-
const crowdloanDeposit = BigInt(100_000_000_000); // 100 TAO
104110
const crowdloanMinContribution = BigInt(1_000_000_000); // 1 TAO
105-
const crowdloanCap = await api.query.SubtensorModule.NetworkLastLockCost.getValue() * BigInt(10);
106111
const crowdloanEnd = await api.query.System.Number.getValue() + 100;
107112
const leasingEmissionsShare = 15;
108113
const leasingEndBlock = await api.query.System.Number.getValue() + 300;
@@ -161,9 +166,7 @@ describe("Test Leasing precompile", () => {
161166
await tx.wait();
162167

163168
const nextCrowdloanId = await api.query.Crowdloan.NextCrowdloanId.getValue();
164-
const crowdloanDeposit = BigInt(100_000_000_000); // 100 TAO
165169
const crowdloanMinContribution = BigInt(1_000_000_000); // 1 TAO
166-
const crowdloanCap = await api.query.SubtensorModule.NetworkLastLockCost.getValue() * BigInt(10);
167170
const crowdloanEnd = await api.query.System.Number.getValue() + 100;
168171
const leasingEmissionsShare = 15;
169172
const leasingEndBlock = await api.query.System.Number.getValue() + 200;

0 commit comments

Comments
 (0)