Add methods for creating auctions and add auction tests #28
@ -63,7 +63,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest --runInBand --verbose --testPathPattern=src",
|
"test": "jest --runInBand --verbose --testPathPattern=src",
|
||||||
"test:authority-auctions": "TEST_AUCTIONS_ENABLED=1 jest --runInBand --verbose src/authority-auction.test.ts",
|
"test:authority-auctions": "TEST_AUCTIONS_ENABLED=1 jest --runInBand --verbose src/authority-auction.test.ts",
|
||||||
"test:auction": "TEST_AUCTIONS_ENABLED=1 jest --runInBand --verbose src/auction.test.ts",
|
"test:auctions": "TEST_AUCTIONS_ENABLED=1 jest --runInBand --verbose src/auction.test.ts",
|
||||||
"test:nameservice-expiry": "TEST_NAMESERVICE_EXPIRY=1 jest --runInBand --verbose src/nameservice-expiry.test.ts",
|
"test:nameservice-expiry": "TEST_NAMESERVICE_EXPIRY=1 jest --runInBand --verbose src/nameservice-expiry.test.ts",
|
||||||
"test:onboarding": "ONBOARDING_ENABLED=1 jest --runInBand --verbose src/onboarding.test.ts",
|
"test:onboarding": "ONBOARDING_ENABLED=1 jest --runInBand --verbose src/onboarding.test.ts",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
|
@ -9,37 +9,37 @@ const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
|||||||
let auctionCreatorAccount: { address: string, privateKey: string, bid?: any };
|
let auctionCreatorAccount: { address: string, privateKey: string, bid?: any };
|
||||||
let bidderAccounts: { address: string, privateKey: string, bid?: any }[] = [];
|
let bidderAccounts: { address: string, privateKey: string, bid?: any }[] = [];
|
||||||
|
|
||||||
|
const commitsDuration = {
|
||||||
|
seconds: Long.fromNumber(60),
|
||||||
|
nanos: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
const revealsDuration = {
|
||||||
|
seconds: Long.fromNumber(60),
|
||||||
|
nanos: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
const commitFee = {
|
||||||
|
denom: DENOM,
|
||||||
|
amount: '1000'
|
||||||
|
};
|
||||||
|
|
||||||
|
const revealFee = {
|
||||||
|
denom: DENOM,
|
||||||
|
amount: '1000'
|
||||||
|
};
|
||||||
|
|
||||||
const createAuctionTests = () => {
|
const createAuctionTests = () => {
|
||||||
let registry: Registry;
|
let registry: Registry;
|
||||||
|
|
||||||
const commitsDuration = {
|
|
||||||
seconds: Long.fromNumber(60),
|
|
||||||
nanos: 0
|
|
||||||
};
|
|
||||||
|
|
||||||
const revealsDuration = {
|
|
||||||
seconds: Long.fromNumber(60),
|
|
||||||
nanos: 0
|
|
||||||
};
|
|
||||||
|
|
||||||
const commitFee = {
|
|
||||||
denom: DENOM,
|
|
||||||
amount: '1000'
|
|
||||||
};
|
|
||||||
|
|
||||||
const revealFee = {
|
|
||||||
denom: DENOM,
|
|
||||||
amount: '1000'
|
|
||||||
};
|
|
||||||
|
|
||||||
let auctionId: string;
|
let auctionId: string;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
console.log('Running auction tests');
|
console.log('Running vickrey auction tests');
|
||||||
|
|
||||||
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
|
||||||
// Create auction creator account and a bidder account
|
// Create auction creator account
|
||||||
const mnenonic1 = Account.generateMnemonic();
|
const mnenonic1 = Account.generateMnemonic();
|
||||||
const auctionCreator = await Account.generateFromMnemonic(mnenonic1);
|
const auctionCreator = await Account.generateFromMnemonic(mnenonic1);
|
||||||
await auctionCreator.init();
|
await auctionCreator.init();
|
||||||
@ -57,7 +57,7 @@ const createAuctionTests = () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Create auction', async () => {
|
test('Create vickrey auction', async () => {
|
||||||
const minimumBid = {
|
const minimumBid = {
|
||||||
denom: 'alnt',
|
denom: 'alnt',
|
||||||
amount: '1000000'
|
amount: '1000000'
|
||||||
@ -89,7 +89,10 @@ const createAuctionTests = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Wait for reveal phase.', (done) => {
|
test('Wait for reveal phase.', (done) => {
|
||||||
setTimeout(done, 60 * 1000);
|
const commitTime = 60 * 1000;
|
||||||
|
const waitTime = commitTime + (6 * 1000);
|
||||||
|
|
||||||
|
setTimeout(done, waitTime);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Reveal bids.', async () => {
|
test('Reveal bids.', async () => {
|
||||||
@ -111,7 +114,10 @@ const createAuctionTests = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Wait for auction completion.', (done) => {
|
test('Wait for auction completion.', (done) => {
|
||||||
setTimeout(done, 60 * 1000);
|
const revealTime = 60 * 1000;
|
||||||
|
const waitTime = revealTime + (6 * 1000);
|
||||||
|
|
||||||
|
setTimeout(done, waitTime);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Check auction winner, authority owner and status.', async () => {
|
test('Check auction winner, authority owner and status.', async () => {
|
||||||
@ -127,7 +133,112 @@ const createAuctionTests = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const createSPAuctionTests = () => {};
|
const createSPAuctionTests = () => {
|
||||||
|
let registry: Registry;
|
||||||
|
let auctionId: string;
|
||||||
|
|
||||||
|
let auctionCreatorAccount: { address: string, privateKey: string, bid?: any };
|
||||||
|
let bidderAccounts: { address: string, privateKey: string, bid?: any }[] = [];
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
console.log('Running service provider auction tests');
|
||||||
|
|
||||||
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
|
||||||
|
// Create auction creator account
|
||||||
|
const mnenonic1 = Account.generateMnemonic();
|
||||||
|
const auctionCreator = await Account.generateFromMnemonic(mnenonic1);
|
||||||
|
await auctionCreator.init();
|
||||||
|
await registry.sendCoins({ denom: DENOM, amount: '1000000000000', destinationAddress: auctionCreator.address }, privateKey, fee);
|
||||||
|
auctionCreatorAccount = { address: auctionCreator.address, privateKey: auctionCreator.privateKey.toString('hex') };
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Setup bidder accounts', async () => {
|
||||||
|
for (let i = 0; i < 4; i++) {
|
||||||
|
const mnenonic = Account.generateMnemonic();
|
||||||
|
const account = await Account.generateFromMnemonic(mnenonic);
|
||||||
|
await account.init();
|
||||||
|
await registry.sendCoins({ denom: DENOM, amount: '20000000', destinationAddress: account.address }, privateKey, fee);
|
||||||
|
bidderAccounts.push({ address: account.address, privateKey: account.privateKey.toString('hex') });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Create service provider auction', async () => {
|
||||||
|
const maxPrice = {
|
||||||
|
denom: 'alnt',
|
||||||
|
amount: '100000000'
|
||||||
|
};
|
||||||
|
|
||||||
|
const auction = await registry.createAuction({
|
||||||
|
commitsDuration,
|
||||||
|
revealsDuration,
|
||||||
|
commitFee,
|
||||||
|
revealFee,
|
||||||
|
minimumBid: undefined,
|
||||||
|
maxPrice,
|
||||||
|
kind: 'service_provider',
|
||||||
|
numProviders: 3,
|
||||||
|
signer: auctionCreatorAccount.address
|
||||||
|
},
|
||||||
|
auctionCreatorAccount.privateKey, fee);
|
||||||
|
|
||||||
|
expect(auction.auction?.id).toBeDefined();
|
||||||
|
auctionId = auction.auction?.id || '';
|
||||||
|
expect(auction.auction?.status).toEqual('commit');
|
||||||
|
});
|
||||||
|
|
||||||
|
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}`);
|
||||||
|
await registry.commitBid({ auctionId, commitHash: bidderAccounts[i].bid.commitHash }, bidderAccounts[i].privateKey, fee);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Wait for reveal phase.', (done) => {
|
||||||
|
const commitTime = 60 * 1000;
|
||||||
|
const waitTime = commitTime + (6 * 1000);
|
||||||
|
|
||||||
|
setTimeout(done, waitTime);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Reveal bids.', async () => {
|
||||||
|
const [auction] = await registry.getAuctionsByIds([auctionId]);
|
||||||
|
expect(auction.status).toEqual('reveal');
|
||||||
|
|
||||||
|
for (let i = 0; i < 4; i++) {
|
||||||
|
await registry.revealBid({ auctionId, reveal: bidderAccounts[i].bid.revealString }, bidderAccounts[i].privateKey, fee);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Check bids are revealed', async () => {
|
||||||
|
const [auction] = await registry.getAuctionsByIds([auctionId]);
|
||||||
|
expect(auction.status).toEqual('reveal');
|
||||||
|
|
||||||
|
auction.bids.forEach((i: number, bid: any) => {
|
||||||
|
expect(bid.status).toEqual('reveal');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Wait for auction completion.', (done) => {
|
||||||
|
const revealTime = 60 * 1000;
|
||||||
|
const waitTime = revealTime + (6 * 1000);
|
||||||
|
|
||||||
|
setTimeout(done, waitTime);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Check auction winner, authority owner and status.', async () => {
|
||||||
|
const [auction] = await registry.getAuctionsByIds([auctionId]);
|
||||||
|
expect(auction.status).toEqual('completed');
|
||||||
|
|
||||||
|
const bidWinners = bidderAccounts.slice(0, 3);
|
||||||
|
|
||||||
|
bidWinners.forEach((winner, index) => {
|
||||||
|
expect(auction.winnerAddresses[index]).toEqual(winner.address);
|
||||||
|
expect(bidWinners[index].bid.reveal.bidAmount).toEqual(`${auction.winnerBids[index].quantity}${auction.winnerBids[index].type}`);
|
||||||
|
});
|
||||||
|
expect(bidWinners[bidWinners.length - 1].bid.reveal.bidAmount).toEqual(`${auction.winnerPrice.quantity}${auction.winnerPrice.type}`);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
describe('Vickrey Auction', () => createAuctionTests());
|
describe('Vickrey Auction', () => createAuctionTests());
|
||||||
describe('Service provider Auction', () => createSPAuctionTests());
|
describe('Service provider Auction', () => createSPAuctionTests());
|
||||||
|
Loading…
Reference in New Issue
Block a user