Add methods for creating auctions and add auction tests #28

Merged
nabarun merged 32 commits from deep-stack/registry-sdk:iv-create-auction-test into main 2024-09-25 13:21:05 +00:00
2 changed files with 29 additions and 18 deletions
Showing only changes of commit 4c719b3e02 - Show all commits

View File

@ -2,20 +2,18 @@ import Long from 'long';
import { Registry, Account, createBid } from './index';
import { getConfig } from './testing/helper';
import { DENOM } from './constants';
import { DENOM, DURATION } from './constants';
jest.setTimeout(30 * 60 * 1000);
const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
let auctionCreatorAccount: { address: string, privateKey: string, bid?: any };
let bidderAccounts: { address: string, privateKey: string, bid?: any }[] = [];
const commitsDuration = {
seconds: Long.fromNumber(60),
seconds: Long.fromNumber(DURATION),
nanos: 0
};
const revealsDuration = {
seconds: Long.fromNumber(60),
seconds: Long.fromNumber(DURATION),
nanos: 0
};
@ -31,9 +29,13 @@ const revealFee = {
const createAuctionTests = () => {
let registry: Registry;
let auctionId: string;
let auctionCreatorAccount: { address: string, privateKey: string, bid?: any };
let bidderAccounts: { address: string, privateKey: string, bid?: any }[] = [];
let bidAmounts: { type: string, quantity: string }[] = [];
beforeAll(async () => {
console.log('Running vickrey auction tests');
@ -83,13 +85,17 @@ const createAuctionTests = () => {
test('Commit bids.', async () => {
for (let i = 0; i < 3; i++) {
bidderAccounts[i].bid = await createBid(chainId, auctionId, bidderAccounts[i].address, `${10000000 + (i * 500)}${DENOM}`);
bidAmounts.push({
type: DENOM,
quantity: (10000000 + (i * 500)).toString()
});
bidderAccounts[i].bid = await createBid(chainId, auctionId, bidderAccounts[i].address, `${bidAmounts[i].quantity}${bidAmounts[i].type}`);
await registry.commitBid({ auctionId, commitHash: bidderAccounts[i].bid.commitHash }, bidderAccounts[i].privateKey, fee);
}
});
test('Wait for reveal phase.', (done) => {
const commitTime = 60 * 1000;
const commitTime = DURATION * 1000;
const waitTime = commitTime + (6 * 1000);
setTimeout(done, waitTime);
@ -108,13 +114,12 @@ const createAuctionTests = () => {
const [auction] = await registry.getAuctionsByIds([auctionId]);
expect(auction.status).toEqual('reveal');
auction.bids.forEach((bid: any) => {
expect(bid.status).toEqual('reveal');
});
const actualBidAmounts = auction.bids.map((bid: any) => bid.bidAmount);
expect(actualBidAmounts).toEqual(expect.arrayContaining(bidAmounts));
});
test('Wait for auction completion.', (done) => {
const revealTime = 60 * 1000;
const revealTime = DURATION * 1000;
const waitTime = revealTime + (6 * 1000);
setTimeout(done, waitTime);
@ -140,6 +145,8 @@ const createSPAuctionTests = () => {
let auctionCreatorAccount: { address: string, privateKey: string, bid?: any };
let bidderAccounts: { address: string, privateKey: string, bid?: any }[] = [];
let bidAmounts: { type: string, quantity: string }[] = [];
beforeAll(async () => {
console.log('Running service provider auction tests');
@ -189,13 +196,17 @@ const createSPAuctionTests = () => {
test('Commit bids.', async () => {
for (let i = 0; i < 4; i++) {
bidderAccounts[i].bid = await createBid(chainId, auctionId, bidderAccounts[i].address, `${100000 + (i * 500)}${DENOM}`);
bidAmounts.push({
type: DENOM,
quantity: (100000 + (i * 500)).toString()
});
bidderAccounts[i].bid = await createBid(chainId, auctionId, bidderAccounts[i].address, `${bidAmounts[i].quantity}${bidAmounts[i].type}`);
await registry.commitBid({ auctionId, commitHash: bidderAccounts[i].bid.commitHash }, bidderAccounts[i].privateKey, fee);
}
});
test('Wait for reveal phase.', (done) => {
const commitTime = 60 * 1000;
const commitTime = DURATION * 1000;
const waitTime = commitTime + (6 * 1000);
setTimeout(done, waitTime);
@ -214,13 +225,12 @@ const createSPAuctionTests = () => {
const [auction] = await registry.getAuctionsByIds([auctionId]);
expect(auction.status).toEqual('reveal');
auction.bids.forEach((i: number, bid: any) => {
expect(bid.status).toEqual('reveal');
});
const actualBidAmounts = auction.bids.map((bid: any) => bid.bidAmount);
expect(actualBidAmounts).toEqual(expect.arrayContaining(bidAmounts));
});
test('Wait for auction completion.', (done) => {
const revealTime = 60 * 1000;
const revealTime = DURATION * 1000;
const waitTime = revealTime + (6 * 1000);
setTimeout(done, waitTime);

View File

@ -1,2 +1,3 @@
export const DENOM = 'alnt';
export const DURATION = 60;
export const DEFAULT_GAS_ESTIMATION_MULTIPLIER = 2;