Add check for bid amount during reveal phase
This commit is contained in:
parent
a647fed60a
commit
4c719b3e02
@ -2,20 +2,18 @@ import Long from 'long';
|
|||||||
|
|
||||||
import { Registry, Account, createBid } from './index';
|
import { Registry, Account, createBid } from './index';
|
||||||
import { getConfig } from './testing/helper';
|
import { getConfig } from './testing/helper';
|
||||||
import { DENOM } from './constants';
|
import { DENOM, DURATION } from './constants';
|
||||||
|
|
||||||
jest.setTimeout(30 * 60 * 1000);
|
jest.setTimeout(30 * 60 * 1000);
|
||||||
const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
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 = {
|
const commitsDuration = {
|
||||||
seconds: Long.fromNumber(60),
|
seconds: Long.fromNumber(DURATION),
|
||||||
nanos: 0
|
nanos: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
const revealsDuration = {
|
const revealsDuration = {
|
||||||
seconds: Long.fromNumber(60),
|
seconds: Long.fromNumber(DURATION),
|
||||||
nanos: 0
|
nanos: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -31,9 +29,13 @@ const revealFee = {
|
|||||||
|
|
||||||
const createAuctionTests = () => {
|
const createAuctionTests = () => {
|
||||||
let registry: Registry;
|
let registry: Registry;
|
||||||
|
|
||||||
let auctionId: string;
|
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 () => {
|
beforeAll(async () => {
|
||||||
console.log('Running vickrey auction tests');
|
console.log('Running vickrey auction tests');
|
||||||
|
|
||||||
@ -83,13 +85,17 @@ const createAuctionTests = () => {
|
|||||||
|
|
||||||
test('Commit bids.', async () => {
|
test('Commit bids.', async () => {
|
||||||
for (let i = 0; i < 3; i++) {
|
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);
|
await registry.commitBid({ auctionId, commitHash: bidderAccounts[i].bid.commitHash }, bidderAccounts[i].privateKey, fee);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Wait for reveal phase.', (done) => {
|
test('Wait for reveal phase.', (done) => {
|
||||||
const commitTime = 60 * 1000;
|
const commitTime = DURATION * 1000;
|
||||||
const waitTime = commitTime + (6 * 1000);
|
const waitTime = commitTime + (6 * 1000);
|
||||||
|
|
||||||
setTimeout(done, waitTime);
|
setTimeout(done, waitTime);
|
||||||
@ -108,13 +114,12 @@ const createAuctionTests = () => {
|
|||||||
const [auction] = await registry.getAuctionsByIds([auctionId]);
|
const [auction] = await registry.getAuctionsByIds([auctionId]);
|
||||||
expect(auction.status).toEqual('reveal');
|
expect(auction.status).toEqual('reveal');
|
||||||
|
|
||||||
auction.bids.forEach((bid: any) => {
|
const actualBidAmounts = auction.bids.map((bid: any) => bid.bidAmount);
|
||||||
expect(bid.status).toEqual('reveal');
|
expect(actualBidAmounts).toEqual(expect.arrayContaining(bidAmounts));
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Wait for auction completion.', (done) => {
|
test('Wait for auction completion.', (done) => {
|
||||||
const revealTime = 60 * 1000;
|
const revealTime = DURATION * 1000;
|
||||||
const waitTime = revealTime + (6 * 1000);
|
const waitTime = revealTime + (6 * 1000);
|
||||||
|
|
||||||
setTimeout(done, waitTime);
|
setTimeout(done, waitTime);
|
||||||
@ -140,6 +145,8 @@ const createSPAuctionTests = () => {
|
|||||||
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 }[] = [];
|
||||||
|
|
||||||
|
let bidAmounts: { type: string, quantity: string }[] = [];
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
console.log('Running service provider auction tests');
|
console.log('Running service provider auction tests');
|
||||||
|
|
||||||
@ -189,13 +196,17 @@ const createSPAuctionTests = () => {
|
|||||||
|
|
||||||
test('Commit bids.', async () => {
|
test('Commit bids.', async () => {
|
||||||
for (let i = 0; i < 4; i++) {
|
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);
|
await registry.commitBid({ auctionId, commitHash: bidderAccounts[i].bid.commitHash }, bidderAccounts[i].privateKey, fee);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Wait for reveal phase.', (done) => {
|
test('Wait for reveal phase.', (done) => {
|
||||||
const commitTime = 60 * 1000;
|
const commitTime = DURATION * 1000;
|
||||||
const waitTime = commitTime + (6 * 1000);
|
const waitTime = commitTime + (6 * 1000);
|
||||||
|
|
||||||
setTimeout(done, waitTime);
|
setTimeout(done, waitTime);
|
||||||
@ -214,13 +225,12 @@ const createSPAuctionTests = () => {
|
|||||||
const [auction] = await registry.getAuctionsByIds([auctionId]);
|
const [auction] = await registry.getAuctionsByIds([auctionId]);
|
||||||
expect(auction.status).toEqual('reveal');
|
expect(auction.status).toEqual('reveal');
|
||||||
|
|
||||||
auction.bids.forEach((i: number, bid: any) => {
|
const actualBidAmounts = auction.bids.map((bid: any) => bid.bidAmount);
|
||||||
expect(bid.status).toEqual('reveal');
|
expect(actualBidAmounts).toEqual(expect.arrayContaining(bidAmounts));
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Wait for auction completion.', (done) => {
|
test('Wait for auction completion.', (done) => {
|
||||||
const revealTime = 60 * 1000;
|
const revealTime = DURATION * 1000;
|
||||||
const waitTime = revealTime + (6 * 1000);
|
const waitTime = revealTime + (6 * 1000);
|
||||||
|
|
||||||
setTimeout(done, waitTime);
|
setTimeout(done, waitTime);
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
export const DENOM = 'alnt';
|
export const DENOM = 'alnt';
|
||||||
|
export const DURATION = 60;
|
||||||
export const DEFAULT_GAS_ESTIMATION_MULTIPLIER = 2;
|
export const DEFAULT_GAS_ESTIMATION_MULTIPLIER = 2;
|
||||||
|
Loading…
Reference in New Issue
Block a user