This repository was archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathauctions.test.ts
673 lines (645 loc) · 26.4 KB
/
auctions.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
import {
Contract,
JWKInterface,
WriteInteractionOptions,
WriteInteractionResponse,
} from 'warp-contracts';
import { calculateAuctionPriceForBlock } from '../src/auctions';
import {
ARNS_NAME_RESERVED_MESSAGE,
ARNS_NON_EXPIRED_NAME_MESSAGE,
AUCTION_SETTINGS,
DEFAULT_UNDERNAME_COUNT,
INVALID_INPUT_MESSAGE,
MINIMUM_ALLOWED_NAME_LENGTH,
SHORT_NAME_RESERVATION_UNLOCK_TIMESTAMP,
} from '../src/constants';
import {
ArNSAuctionData,
BlockHeight,
IOState,
IOToken,
mIOToken,
} from '../src/types';
import { ANT_CONTRACT_IDS } from './utils/constants';
import {
getCurrentBlock,
getLocalArNSContractKey,
getLocalWallet,
mineBlocks,
} from './utils/helper';
import { arweave, warp } from './utils/services';
describe('Auctions', () => {
let contract: Contract<IOState>;
let srcContractId: string;
let nonContractOwner: JWKInterface;
let nonContractOwnerAddress: string;
let prevState: IOState;
beforeAll(async () => {
srcContractId = getLocalArNSContractKey('id');
nonContractOwner = getLocalWallet(1);
contract = warp.contract<IOState>(srcContractId).connect(nonContractOwner);
nonContractOwnerAddress = await arweave.wallets.getAddress(
nonContractOwner,
);
contract.connect(nonContractOwner);
});
beforeEach(async () => {
// tick so we are always working off freshest state
await contract.writeInteraction({ function: 'tick' });
prevState = (await contract.readState()).cachedValue.state as IOState;
});
afterEach(() => {
contract.connect(nonContractOwner);
});
describe('submits an auction bid', () => {
describe('with bad input', () => {
it.each([
'',
'*&*##$%#',
'-leading',
'this-is-a-looong-name-a-verrrryyyyy-loooooong-name-that-is-too-long',
'test.subdomain.name',
false,
true,
0,
1,
3.5,
])(
'should throw an error when an invalid name is submitted: %s',
async (badName) => {
const auctionBid = {
name: badName,
contractTxId: ANT_CONTRACT_IDS[0],
type: 'lease',
};
const writeInteraction = await writeInteractionOrFail(
contract,
{
function: 'submitAuctionBid',
...auctionBid,
},
{
disableBundling: true,
},
);
expect(writeInteraction?.originalTxId).not.toBe(undefined);
const { cachedValue } = await contract.readState();
expect(Object.keys(cachedValue.errorMessages)).toContain(
writeInteraction?.originalTxId,
);
expect(
cachedValue.errorMessages[writeInteraction?.originalTxId],
).toEqual(expect.stringContaining(INVALID_INPUT_MESSAGE));
expect(cachedValue.state).toEqual(prevState);
},
);
it.each([
'',
'*&*##$%#',
'-leading',
'this-is-a-looong-name-a-verrrryyyyy-loooooong-name-that-is-too-long',
'test.subdomain.name',
false,
true,
0,
1,
3.5,
])(
'should throw an error when an invalid type is submitted: %s',
async (badType) => {
const auctionBid = {
name: 'apple',
contractTxId: ANT_CONTRACT_IDS[0],
type: badType,
};
const writeInteraction = await writeInteractionOrFail(
contract,
{
function: 'submitAuctionBid',
...auctionBid,
},
{
disableBundling: true,
},
);
expect(writeInteraction?.originalTxId).not.toBe(undefined);
const { cachedValue } = await contract.readState();
expect(Object.keys(cachedValue.errorMessages)).toContain(
writeInteraction?.originalTxId,
);
expect(
cachedValue.errorMessages[writeInteraction?.originalTxId],
).toEqual(expect.stringContaining(INVALID_INPUT_MESSAGE));
expect(cachedValue.state).toEqual(prevState);
},
);
it.each([
'',
'*&*##$%#',
'-leading',
'this-is-a-looong-name-a-verrrryyyyy-loooooong-name-that-is-too-long',
'test.subdomain.name',
false,
true,
0,
1,
3.5,
])(
'should throw an error when an invalid contract TX id is provided: %s',
async (badTxId) => {
const auctionBid = {
name: 'apple',
contractTxId: badTxId,
type: 'lease',
};
const writeInteraction = await writeInteractionOrFail(
contract,
{
function: 'submitAuctionBid',
...auctionBid,
},
{
disableBundling: true,
},
);
expect(writeInteraction?.originalTxId).not.toBe(undefined);
const { cachedValue } = await contract.readState();
expect(Object.keys(cachedValue.errorMessages)).toContain(
writeInteraction?.originalTxId,
);
expect(
cachedValue.errorMessages[writeInteraction?.originalTxId],
).toEqual(expect.stringContaining(INVALID_INPUT_MESSAGE));
expect(cachedValue.state).toEqual(prevState);
},
);
});
describe('with valid input', () => {
describe('for a lease', () => {
describe('for a non-existent auction', () => {
let auctionTxId: string;
let auctionObj: ArNSAuctionData | undefined;
const auctionBid = {
name: 'apple',
contractTxId: ANT_CONTRACT_IDS[0],
};
it('should create the initial auction object', async () => {
const writeInteraction = await writeInteractionOrFail(contract, {
function: 'submitAuctionBid',
...auctionBid,
});
expect(writeInteraction?.originalTxId).not.toBe(undefined);
const { cachedValue } = await contract.readState();
const { auctions, balances } = cachedValue.state as IOState;
expect(auctions[auctionBid.name]).not.toBe(undefined);
expect(auctions[auctionBid.name]).toEqual(
expect.objectContaining({
floorPrice: expect.any(Number),
startPrice: expect.any(Number),
type: 'lease',
endHeight:
(await getCurrentBlock(arweave)).valueOf() +
AUCTION_SETTINGS.auctionDuration,
startHeight: (await getCurrentBlock(arweave)).valueOf(),
initiator: nonContractOwnerAddress,
contractTxId: ANT_CONTRACT_IDS[0],
years: 1,
}),
);
expect(balances[nonContractOwnerAddress]).toEqual(
prevState.balances[nonContractOwnerAddress] -
auctions[auctionBid.name].floorPrice,
);
// for the remaining tests
auctionObj = auctions[auctionBid.name];
auctionTxId = writeInteraction?.originalTxId;
// TODO: Check for incremented state
});
describe('another bid', () => {
it('should throw an error when the bid does not meet the minimum required', async () => {
const auctionBid = {
name: 'apple',
qty: new IOToken(100).toMIO().valueOf(), // not going to win it
contractTxId: ANT_CONTRACT_IDS[0],
};
// connect using another wallet
const separateWallet = getLocalWallet(2);
contract.connect(separateWallet);
const writeInteraction = await writeInteractionOrFail(contract, {
function: 'submitAuctionBid',
...auctionBid,
});
expect(writeInteraction?.originalTxId).not.toBeUndefined();
const { cachedValue } = await contract.readState();
expect(Object.keys(cachedValue.errorMessages)).toContain(
writeInteraction?.originalTxId,
);
expect(
cachedValue.errorMessages[writeInteraction?.originalTxId],
).toEqual(
expect.stringContaining(
`The bid (${new IOToken(100)
.toMIO()
.valueOf()} mIO) is less than the current required minimum bid`,
),
);
const { auctions, records, balances } =
cachedValue.state as IOState;
expect(auctions[auctionBid.name]).toEqual(auctionObj);
expect(records[auctionBid.name]).toBeUndefined();
expect(balances).toEqual(prevState.balances);
});
it('should update the records object when a winning bid comes in', async () => {
// fast forward to the last allowed block for the auction bid
await mineBlocks(arweave, 5);
if (!auctionObj) {
throw new Error('auctionObj is undefined');
}
const winningBidQty = calculateAuctionPriceForBlock({
startHeight: new BlockHeight(auctionObj.startHeight),
startPrice: new mIOToken(auctionObj.startPrice),
floorPrice: new mIOToken(auctionObj.floorPrice),
currentBlockHeight: await getCurrentBlock(arweave),
auctionSettings: AUCTION_SETTINGS,
}).valueOf();
const auctionBid = {
name: 'apple',
qty: winningBidQty,
contractTxId: ANT_CONTRACT_IDS[1],
};
// connect using another wallet
const separateWallet = getLocalWallet(2);
contract.connect(separateWallet);
const winnerAddress = await arweave.wallets.getAddress(
separateWallet,
);
const writeInteraction = await contract.writeInteraction({
function: 'submitAuctionBid',
...auctionBid,
});
const pricePaidForBlock = calculateAuctionPriceForBlock({
startHeight: new BlockHeight(auctionObj.startHeight),
startPrice: new mIOToken(auctionObj.startPrice),
floorPrice: new mIOToken(auctionObj.floorPrice),
currentBlockHeight: await getCurrentBlock(arweave),
auctionSettings: AUCTION_SETTINGS,
}).valueOf();
expect(writeInteraction?.originalTxId).not.toBeUndefined();
const { cachedValue } = await contract.readState();
expect(cachedValue.errorMessages).not.toContain(auctionTxId);
const { auctions, records, balances } =
cachedValue.state as IOState;
expect(auctions[auctionBid.name]).toBeUndefined();
expect(records[auctionBid.name]).toEqual({
contractTxId: ANT_CONTRACT_IDS[1],
endTimestamp: expect.any(Number),
startTimestamp: expect.any(Number),
undernames: expect.any(Number),
purchasePrice: pricePaidForBlock,
type: 'lease',
});
expect(balances[winnerAddress]).toEqual(
prevState.balances[winnerAddress] - pricePaidForBlock,
);
expect(balances[auctionObj.initiator]).toEqual(
prevState.balances[auctionObj.initiator] +
auctionObj.floorPrice,
);
expect(balances[srcContractId]).toEqual(
// Uses the smartweave contract ID to act as the protocol balance
prevState.balances[srcContractId] + pricePaidForBlock,
);
// clear out the auction obj
auctionObj = undefined;
});
});
it('should throw an error if the name already exist in records', async () => {
const auctionBid = {
name: 'apple',
contractTxId: ANT_CONTRACT_IDS[0],
};
// connect using another wallet
const separateWallet = getLocalWallet(2);
contract.connect(separateWallet);
const writeInteraction = await writeInteractionOrFail(contract, {
function: 'submitAuctionBid',
...auctionBid,
});
expect(writeInteraction?.originalTxId).not.toBe(undefined);
const { cachedValue } = await contract.readState();
const { auctions, balances } = cachedValue.state as IOState;
expect(Object.keys(cachedValue.errorMessages)).toContain(
writeInteraction?.originalTxId,
);
expect(
cachedValue.errorMessages[writeInteraction?.originalTxId],
).toEqual(ARNS_NON_EXPIRED_NAME_MESSAGE);
expect(auctions[auctionBid.name]).toBeUndefined();
expect(balances).toEqual(prevState.balances);
});
it('should throw an error if a name is reserved that has no expiration', async () => {
const auctionBid = {
name: 'www',
contractTxId: ANT_CONTRACT_IDS[0],
};
const writeInteraction = await writeInteractionOrFail(contract, {
function: 'submitAuctionBid',
...auctionBid,
});
expect(writeInteraction?.originalTxId).not.toBe(undefined);
const { cachedValue } = await contract.readState();
const { auctions, balances } = cachedValue.state as IOState;
expect(Object.keys(cachedValue.errorMessages)).toContain(
writeInteraction?.originalTxId,
);
expect(
cachedValue.errorMessages[writeInteraction?.originalTxId],
).toEqual(ARNS_NAME_RESERVED_MESSAGE);
expect(auctions[auctionBid.name]).toBeUndefined();
expect(balances).toEqual(prevState.balances);
});
it('should throw an error if less than the short name minimum length and short name expiration has not passed', async () => {
const auctionBid = {
name: 'ibm',
contractTxId: ANT_CONTRACT_IDS[0],
};
const writeInteraction = await writeInteractionOrFail(contract, {
function: 'submitAuctionBid',
...auctionBid,
});
expect(writeInteraction?.originalTxId).not.toBe(undefined);
const { cachedValue } = await contract.readState();
const { auctions, balances } = cachedValue.state as IOState;
expect(Object.keys(cachedValue.errorMessages)).toContain(
writeInteraction?.originalTxId,
);
expect(
cachedValue.errorMessages[writeInteraction?.originalTxId],
).toEqual(
`Name is less than ${MINIMUM_ALLOWED_NAME_LENGTH} characters. It will be available for auction after ${SHORT_NAME_RESERVATION_UNLOCK_TIMESTAMP}.`,
);
expect(auctions[auctionBid.name]).toBeUndefined();
expect(balances).toEqual(prevState.balances);
});
it('should throw an error if a name is reserved for a specific wallet without an expiration', async () => {
const auctionBid = {
name: 'www',
contractTxId: ANT_CONTRACT_IDS[0],
};
// connect using another wallet
const separateWallet = getLocalWallet(2);
contract.connect(separateWallet);
const writeInteraction = await writeInteractionOrFail(contract, {
function: 'submitAuctionBid',
...auctionBid,
});
expect(writeInteraction?.originalTxId).not.toBe(undefined);
const { cachedValue } = await contract.readState();
const { auctions, balances } = cachedValue.state as IOState;
expect(Object.keys(cachedValue.errorMessages)).toContain(
writeInteraction?.originalTxId,
);
expect(
cachedValue.errorMessages[writeInteraction?.originalTxId],
).toEqual(ARNS_NAME_RESERVED_MESSAGE);
expect(auctions[auctionBid.name]).toBeUndefined();
expect(balances).toEqual(prevState.balances);
});
it('should start the auction if the reserved target submits the auction bid', async () => {
const auctionBid = {
name: 'auction',
contractTxId: ANT_CONTRACT_IDS[0],
};
const writeInteraction = await writeInteractionOrFail(contract, {
function: 'submitAuctionBid',
...auctionBid,
});
expect(writeInteraction?.originalTxId).not.toBe(undefined);
const { cachedValue } = await contract.readState();
const { auctions, balances, reserved } =
cachedValue.state as IOState;
expect(Object.keys(cachedValue.errorMessages)).not.toContain(
writeInteraction?.originalTxId,
);
expect(auctions[auctionBid.name]).toEqual({
floorPrice: expect.any(Number),
startPrice: expect.any(Number),
type: 'lease',
startHeight: (await getCurrentBlock(arweave)).valueOf(),
endHeight:
(await getCurrentBlock(arweave)).valueOf() +
AUCTION_SETTINGS.auctionDuration,
initiator: nonContractOwnerAddress,
contractTxId: ANT_CONTRACT_IDS[0],
years: 1,
});
expect(balances[nonContractOwnerAddress]).toEqual(
prevState.balances[nonContractOwnerAddress] -
auctions[auctionBid.name].floorPrice,
);
expect(reserved[auctionBid.name]).toBeUndefined();
});
});
});
});
describe('for a permabuy', () => {
let auctionTxId: string;
let auctionObj: ArNSAuctionData;
const auctionBid = {
name: 'microsoft',
contractTxId: ANT_CONTRACT_IDS[0],
type: 'permabuy',
};
it('should create the initial auction object', async () => {
const writeInteraction = await writeInteractionOrFail(contract, {
function: 'submitAuctionBid',
...auctionBid,
});
expect(writeInteraction?.originalTxId).not.toBe(undefined);
const { cachedValue } = await contract.readState();
const { auctions, balances } = cachedValue.state as IOState;
expect(auctions[auctionBid.name]).not.toBe(undefined);
expect(auctions[auctionBid.name]).toEqual({
floorPrice: expect.any(Number),
startPrice: expect.any(Number),
type: 'permabuy',
startHeight: (await getCurrentBlock(arweave)).valueOf(),
endHeight:
(await getCurrentBlock(arweave)).valueOf() +
AUCTION_SETTINGS.auctionDuration,
initiator: nonContractOwnerAddress,
contractTxId: ANT_CONTRACT_IDS[0],
});
expect(balances[nonContractOwnerAddress]).toEqual(
prevState.balances[nonContractOwnerAddress] -
auctions[auctionBid.name].floorPrice,
);
// for the remaining tests
auctionObj = auctions[auctionBid.name];
auctionTxId = writeInteraction?.originalTxId;
// TODO: Check that number of purchases is incremented
});
it('should update the records object and increment demand factor for the current period when a winning bid comes in', async () => {
const { demandFactoring: prevDemandFactoringData } = prevState;
const prevDemandFactorPurchasesForPeriod =
prevDemandFactoringData.purchasesThisPeriod;
// fast forward to lower auction price
await mineBlocks(arweave, 5);
const winningBidQty = calculateAuctionPriceForBlock({
startHeight: new BlockHeight(auctionObj.startHeight),
startPrice: new mIOToken(auctionObj.startPrice),
floorPrice: new mIOToken(auctionObj.floorPrice),
currentBlockHeight: await getCurrentBlock(arweave),
auctionSettings: AUCTION_SETTINGS,
}).valueOf();
const auctionBid = {
name: 'microsoft',
qty: winningBidQty,
contractTxId: ANT_CONTRACT_IDS[1],
};
// connect using another wallet
const separateWallet = getLocalWallet(2);
contract.connect(separateWallet);
const winnerAddress = await arweave.wallets.getAddress(separateWallet);
const writeInteraction = await contract.writeInteraction({
function: 'submitAuctionBid',
...auctionBid,
});
const pricePaidForBlock = calculateAuctionPriceForBlock({
startHeight: new BlockHeight(auctionObj.startHeight),
startPrice: new mIOToken(auctionObj.startPrice),
floorPrice: new mIOToken(auctionObj.floorPrice),
currentBlockHeight: await getCurrentBlock(arweave),
auctionSettings: AUCTION_SETTINGS,
}).valueOf();
expect(writeInteraction?.originalTxId).not.toBeUndefined();
const { cachedValue } = await contract.readState();
expect(cachedValue.errorMessages).not.toContain(auctionTxId);
const {
auctions,
records,
balances,
demandFactoring: newDemandFactoringData,
} = cachedValue.state as IOState;
expect(records[auctionBid.name]).toEqual({
contractTxId: ANT_CONTRACT_IDS[1],
type: 'permabuy',
startTimestamp: expect.any(Number),
undernames: expect.any(Number),
purchasePrice: pricePaidForBlock,
});
expect(auctions[auctionBid.name]).toBeUndefined();
expect(balances[winnerAddress]).toEqual(
prevState.balances[winnerAddress] - pricePaidForBlock,
);
expect(balances[auctionObj.initiator]).toEqual(
prevState.balances[auctionObj.initiator] + auctionObj.floorPrice,
);
expect(balances[srcContractId]).toEqual(
prevState.balances[srcContractId] + pricePaidForBlock,
);
expect(newDemandFactoringData.purchasesThisPeriod).toEqual(
prevDemandFactorPurchasesForPeriod + 1,
);
});
});
describe('for an eager initiator', () => {
let auctionTxId: string;
let auctionObj: ArNSAuctionData;
const auctionBid = {
name: 'tesla',
contractTxId: ANT_CONTRACT_IDS[0],
};
it('should create the initial auction object', async () => {
const writeInteraction = await writeInteractionOrFail(contract, {
function: 'submitAuctionBid',
...auctionBid,
});
expect(writeInteraction?.originalTxId).not.toBe(undefined);
const { cachedValue } = await contract.readState();
const { auctions, balances } = cachedValue.state as IOState;
expect(auctions[auctionBid.name]).not.toBe(undefined);
expect(auctions[auctionBid.name]).toEqual({
floorPrice: expect.any(Number),
startPrice: expect.any(Number),
type: 'lease',
startHeight: (await getCurrentBlock(arweave)).valueOf(),
endHeight:
(await getCurrentBlock(arweave)).valueOf() +
AUCTION_SETTINGS.auctionDuration,
initiator: nonContractOwnerAddress,
contractTxId: ANT_CONTRACT_IDS[0],
years: 1,
});
expect(balances[nonContractOwnerAddress]).toEqual(
prevState.balances[nonContractOwnerAddress] -
auctions[auctionBid.name].floorPrice,
);
// for the remaining tests
auctionObj = auctions[auctionBid.name];
auctionTxId = writeInteraction?.originalTxId;
});
it('should update the records when the caller is the initiator, and only withdraw the difference of the current bid to the original floor price that was already withdrawn from the initiator', async () => {
// fast forward a few blocks, then construct winning bid
await mineBlocks(arweave, 5);
const winningBidQty = calculateAuctionPriceForBlock({
startHeight: new BlockHeight(auctionObj.startHeight),
startPrice: new mIOToken(auctionObj.startPrice),
floorPrice: new mIOToken(auctionObj.floorPrice),
currentBlockHeight: await getCurrentBlock(arweave),
auctionSettings: AUCTION_SETTINGS,
}).valueOf();
const auctionBid = {
name: 'tesla',
qty: winningBidQty,
contractTxId: ANT_CONTRACT_IDS[1],
};
const writeInteraction = await contract.writeInteraction({
function: 'submitAuctionBid',
...auctionBid,
});
// we always take the lesser of the submitted and the cost of auction at a given block
const pricePaidForBlock = calculateAuctionPriceForBlock({
startHeight: new BlockHeight(auctionObj.startHeight),
startPrice: new mIOToken(auctionObj.startPrice),
floorPrice: new mIOToken(auctionObj.floorPrice),
currentBlockHeight: await getCurrentBlock(arweave),
auctionSettings: AUCTION_SETTINGS,
}).valueOf();
expect(writeInteraction?.originalTxId).not.toBeUndefined();
const { cachedValue } = await contract.readState();
expect(cachedValue.errorMessages).not.toContain(auctionTxId);
const { auctions, records, balances } = cachedValue.state as IOState;
expect(auctions[auctionBid.name]).toBeUndefined();
expect(records[auctionBid.name]).toEqual({
contractTxId: ANT_CONTRACT_IDS[1],
type: 'lease',
endTimestamp: expect.any(Number),
startTimestamp: expect.any(Number),
undernames: DEFAULT_UNDERNAME_COUNT,
purchasePrice: pricePaidForBlock,
});
const excessValueForInitiator =
pricePaidForBlock - auctionObj.floorPrice;
expect(balances[nonContractOwnerAddress]).toEqual(
prevState.balances[nonContractOwnerAddress] - excessValueForInitiator,
);
expect(balances[srcContractId]).toEqual(
prevState.balances[srcContractId] + pricePaidForBlock,
);
});
});
});
});
async function writeInteractionOrFail<Input = unknown>(
contract: Contract<IOState>,
input: Input,
options?: WriteInteractionOptions,
): Promise<WriteInteractionResponse> {
const writeInteraction = await contract.writeInteraction(input, options);
if (!writeInteraction) {
throw new Error('Contract write interaction returned null unexpectedly');
}
return writeInteraction;
}