Increment package version
All checks were successful
Lint & Build / lint_and_build (20.x) (pull_request) Successful in 1m52s
Tests / sdk_tests (pull_request) Successful in 32m23s

This commit is contained in:
Prathamesh Musale 2024-09-25 17:04:54 +05:30
parent 5659864611
commit 8d02ebe4ec
3 changed files with 48 additions and 44 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@cerc-io/registry-sdk",
"version": "0.2.9",
"version": "0.2.10",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"repository": "git@github.com:cerc-io/registry-sdk.git",

View File

@ -6,14 +6,14 @@ import { INVALID_BID_ERROR, OWNER_MISMATCH_ERROR, RELEASE_FUNDS_ERROR } from './
jest.setTimeout(30 * 60 * 1000);
const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
const duration = 60;
const txFees = Number(fee.amount[0].amount);
const commitFee = '1000';
const revealFee = '1000';
const DURATION = 60;
const TX_FEES = Number(fee.amount[0].amount);
const COMMIT_FEE = '1000';
const REVEAL_FEE = '1000';
const creatorInitialBalance = 1000000000000;
const bidderInitialBalance = 20000000;
const lowestBidAmount = 10000000;
const CREATOR_INITIAL_BALANCE = 1000000000000;
const BIDDER_INITIAL_BALANCE = 20000000;
const LOWEST_BID_AMOUNT = 10000000;
const auctionTests = () => {
let registry: Registry;
@ -29,14 +29,14 @@ const auctionTests = () => {
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
// Create auction creator account
const auctionCreator = await createTestAccounts(1);
await registry.sendCoins({ denom: DENOM, amount: creatorInitialBalance.toString(), destinationAddress: auctionCreator[0].address }, privateKey, fee);
auctionCreatorAccount = { address: auctionCreator[0].address, privateKey: auctionCreator[0].privateKey.toString('hex') };
const [auctionCreator] = await createTestAccounts(1);
await registry.sendCoins({ denom: DENOM, amount: CREATOR_INITIAL_BALANCE.toString(), destinationAddress: auctionCreator.address }, privateKey, fee);
auctionCreatorAccount = { address: auctionCreator.address, privateKey: auctionCreator.privateKey.toString('hex') };
// Create bidder accounts
const accounts = await createTestAccounts(numBidders);
for (let i = 0; i < numBidders; i++) {
await registry.sendCoins({ denom: DENOM, amount: bidderInitialBalance.toString(), destinationAddress: accounts[i].address }, privateKey, fee);
await registry.sendCoins({ denom: DENOM, amount: BIDDER_INITIAL_BALANCE.toString(), destinationAddress: accounts[i].address }, privateKey, fee);
bidderAccounts.push({ address: accounts[i].address, privateKey: accounts[i].privateKey.toString('hex') });
}
});
@ -46,11 +46,11 @@ const auctionTests = () => {
const auction = await registry.createAuction(
{
commitsDuration: duration.toString(),
revealsDuration: duration.toString(),
commitsDuration: DURATION.toString(),
revealsDuration: DURATION.toString(),
denom: DENOM,
commitFee,
revealFee,
commitFee: COMMIT_FEE,
revealFee: REVEAL_FEE,
minimumBid
},
auctionCreatorAccount.privateKey,
@ -58,13 +58,15 @@ const auctionTests = () => {
);
expect(auction.auction?.id).toBeDefined();
auctionId = auction.auction?.id || '';
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
auctionId = auction.auction!.id;
expect(auction.auction?.status).toEqual('commit');
});
test('Commit bids.', async () => {
for (let i = 0; i < numBidders; i++) {
bidAmounts.push((lowestBidAmount + (i * 500)).toString());
bidAmounts.push((LOWEST_BID_AMOUNT + (i * 500)).toString());
bidderAccounts[i].bid = await createBid(chainId, auctionId, bidderAccounts[i].address, `${bidAmounts[i]}${DENOM}`);
await registry.commitBid({ auctionId, commitHash: bidderAccounts[i].bid.commitHash }, bidderAccounts[i].privateKey, fee);
}
@ -78,7 +80,7 @@ const auctionTests = () => {
});
test('Wait for reveal phase.', (done) => {
const commitTime = duration * 1000;
const commitTime = DURATION * 1000;
const waitTime = commitTime + (6 * 1000);
setTimeout(done, waitTime);
@ -107,13 +109,13 @@ const auctionTests = () => {
// Check that the bid amounts are locked after reveal phase
for (let i = 0; i < numBidders; i++) {
// The bid amount, commit fee, reveal fee and tx fees (for commit and reveal txs) will be deducted from the bidder's acoount
const expectedBalance = bidderInitialBalance - parseInt(bidAmounts[i]) - (2 * txFees) - parseInt(commitFee) - parseInt(revealFee);
const expectedBalance = BIDDER_INITIAL_BALANCE - parseInt(bidAmounts[i]) - (2 * TX_FEES) - parseInt(COMMIT_FEE) - parseInt(REVEAL_FEE);
await checkAccountBalance(registry, bidderAccounts[i].address, expectedBalance);
}
});
test('Wait for auction completion.', (done) => {
const revealTime = duration * 1000;
const revealTime = DURATION * 1000;
const waitTime = revealTime + (6 * 1000);
setTimeout(done, waitTime);
@ -135,7 +137,7 @@ const auctionTests = () => {
const winningPriceAmount = parseInt(auction.winnerPrice.quantity);
// The winning price will get deducted after auction completion
const expectedBalance = bidderInitialBalance - winningPriceAmount - (2 * txFees) - parseInt(commitFee);
const expectedBalance = BIDDER_INITIAL_BALANCE - winningPriceAmount - (2 * TX_FEES) - parseInt(COMMIT_FEE);
await checkAccountBalance(registry, highestBidder.address, expectedBalance);
});
};
@ -152,20 +154,20 @@ const providerAuctionTestsWithBids = (bidAmounts: number[], numProviders: number
let otherAccount: { address: string, privateKey: string };
const numBidders = bidAmounts.length;
const maxPrice = 10 * lowestBidAmount;
const maxPrice = 10 * LOWEST_BID_AMOUNT;
beforeAll(async () => {
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
// Create auction creator account
const auctionCreator = await createTestAccounts(1);
await registry.sendCoins({ denom: DENOM, amount: creatorInitialBalance.toString(), destinationAddress: auctionCreator[0].address }, privateKey, fee);
auctionCreatorAccount = { address: auctionCreator[0].address, privateKey: auctionCreator[0].privateKey.toString('hex') };
const [auctionCreator] = await createTestAccounts(1);
await registry.sendCoins({ denom: DENOM, amount: CREATOR_INITIAL_BALANCE.toString(), destinationAddress: auctionCreator.address }, privateKey, fee);
auctionCreatorAccount = { address: auctionCreator.address, privateKey: auctionCreator.privateKey.toString('hex') };
// Create bidder accounts
const accounts = await createTestAccounts(numBidders);
for (let i = 0; i < numBidders; i++) {
await registry.sendCoins({ denom: DENOM, amount: bidderInitialBalance.toString(), destinationAddress: accounts[i].address }, privateKey, fee);
await registry.sendCoins({ denom: DENOM, amount: BIDDER_INITIAL_BALANCE.toString(), destinationAddress: accounts[i].address }, privateKey, fee);
bidderAccounts.push({ address: accounts[i].address, privateKey: accounts[i].privateKey.toString('hex') });
}
@ -173,18 +175,18 @@ const providerAuctionTestsWithBids = (bidAmounts: number[], numProviders: number
const otherAcc = await Account.generateFromMnemonic(mnenonic3);
await otherAcc.init();
await registry.sendCoins({ denom: DENOM, amount: creatorInitialBalance.toString(), destinationAddress: otherAcc.address }, privateKey, fee);
await registry.sendCoins({ denom: DENOM, amount: CREATOR_INITIAL_BALANCE.toString(), destinationAddress: otherAcc.address }, privateKey, fee);
otherAccount = { address: otherAcc.address, privateKey: otherAcc.privateKey.toString('hex') };
});
test('Create a provider auction', async () => {
const auction = await registry.createProviderAuction(
{
commitsDuration: duration.toString(),
revealsDuration: duration.toString(),
commitsDuration: DURATION.toString(),
revealsDuration: DURATION.toString(),
denom: DENOM,
commitFee,
revealFee,
commitFee: COMMIT_FEE,
revealFee: REVEAL_FEE,
maxPrice: maxPrice.toString(),
numProviders
},
@ -192,11 +194,13 @@ const providerAuctionTestsWithBids = (bidAmounts: number[], numProviders: number
);
expect(auction.auction?.id).toBeDefined();
auctionId = auction.auction?.id || '';
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
auctionId = auction.auction!.id;
expect(auction.auction?.status).toEqual('commit');
// The locked amount and tx fees are deducted from the auction creator's account
const expectedBalance = creatorInitialBalance - (maxPrice * numProviders) - txFees;
const expectedBalance = CREATOR_INITIAL_BALANCE - (maxPrice * numProviders) - TX_FEES;
await checkAccountBalance(registry, auctionCreatorAccount.address, expectedBalance);
});
@ -225,7 +229,7 @@ const providerAuctionTestsWithBids = (bidAmounts: number[], numProviders: number
});
test('Wait for reveal phase.', (done) => {
const commitTime = duration * 1000;
const commitTime = DURATION * 1000;
const waitTime = commitTime + (6 * 1000);
setTimeout(done, waitTime);
@ -268,7 +272,7 @@ const providerAuctionTestsWithBids = (bidAmounts: number[], numProviders: number
});
test('Wait for auction completion.', (done) => {
const revealTime = duration * 1000;
const revealTime = DURATION * 1000;
const waitTime = revealTime + (6 * 1000);
setTimeout(done, waitTime);
@ -292,7 +296,7 @@ const providerAuctionTestsWithBids = (bidAmounts: number[], numProviders: number
// The total winning amount will get deducted and the leftover locked amount is returned
const totalWinningAmount = parseInt(auction.winnerPrice.quantity) * winningBidders.length;
const expectedCreatorBalance = creatorInitialBalance - totalWinningAmount - txFees;
const expectedCreatorBalance = CREATOR_INITIAL_BALANCE - totalWinningAmount - TX_FEES;
await checkAccountBalance(registry, auctionCreatorAccount.address, expectedCreatorBalance);
// Funds should not be given to winners on auction completion
@ -302,7 +306,7 @@ const providerAuctionTestsWithBids = (bidAmounts: number[], numProviders: number
expect(auction.winnerAddresses[i]).toEqual(bidWinner.address);
expect(`${auction.winnerBids[i].quantity}${auction.winnerBids[i].type}`).toEqual(bidWinner.bid.reveal.bidAmount);
const expectedBidderBalance = bidderInitialBalance - (2 * txFees) - parseInt(commitFee);
const expectedBidderBalance = BIDDER_INITIAL_BALANCE - (2 * TX_FEES) - parseInt(COMMIT_FEE);
await checkAccountBalance(registry, bidWinner.address, expectedBidderBalance);
}
});
@ -328,7 +332,7 @@ const providerAuctionTestsWithBids = (bidAmounts: number[], numProviders: number
expect(auctionObj.auction?.fundsReleased).toBe(true);
// Auction winners get the winning amount after funds are released
const expectedBidderBalance = bidderInitialBalance + winningBidAmount - (2 * txFees) - parseInt(commitFee);
const expectedBidderBalance = BIDDER_INITIAL_BALANCE + winningBidAmount - (2 * TX_FEES) - parseInt(COMMIT_FEE);
for (let i = 0; i < winningBidders.length; i++) {
const bidWinner = winningBidders[i];
@ -342,10 +346,10 @@ const providerAuctionTestsWithBids = (bidAmounts: number[], numProviders: number
for (const bidder of losingBidders) {
let expectedBidderBalance: number;
if (invalidBidderAddress !== bidder.address) {
expectedBidderBalance = bidderInitialBalance - (2 * txFees) - parseInt(commitFee);
expectedBidderBalance = BIDDER_INITIAL_BALANCE - (2 * TX_FEES) - parseInt(COMMIT_FEE);
} else {
// Bid is invalid, reveal fees are not returned
expectedBidderBalance = bidderInitialBalance - (2 * txFees) - parseInt(commitFee) - parseInt(revealFee);
expectedBidderBalance = BIDDER_INITIAL_BALANCE - (2 * TX_FEES) - parseInt(COMMIT_FEE) - parseInt(REVEAL_FEE);
}
await checkAccountBalance(registry, bidder.address, expectedBidderBalance);

View File

@ -5,7 +5,7 @@ import { DENOM } from './constants';
jest.setTimeout(30 * 60 * 1000);
const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
const duration = 60;
const DURATION = 60;
const auctionTests = (numBidders = 3) => {
let registry: Registry;
@ -67,7 +67,7 @@ const auctionTests = (numBidders = 3) => {
});
test('Wait for reveal phase.', (done) => {
const commitTime = duration * 1000;
const commitTime = DURATION * 1000;
const waitTime = commitTime + (6 * 1000);
setTimeout(done, waitTime);
@ -92,7 +92,7 @@ const auctionTests = (numBidders = 3) => {
});
test('Wait for auction completion.', (done) => {
const revealTime = duration * 1000;
const revealTime = DURATION * 1000;
const waitTime = revealTime + (6 * 1000);
setTimeout(done, waitTime);