Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

feat(PE-4385) add start timestamp #42

Merged
merged 7 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ validations.mjs

# keys
**key**.json
wallets

# warp
cache
Expand Down
19 changes: 17 additions & 2 deletions json_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,24 @@
"properties": {
"tier": { "type": "string", "format": "uuid" },
"contractTxID": { "type": "string", "format": "uuid" },
"endTimestamp": { "type": "integer" }
"endTimestamp": { "type": "integer" },
"startTimestamp": { "type": "integer" }
},
"required": ["tier", "contractTxID", "endTimestamp"],
"required": ["tier", "contractTxID", "startTimestamp"],
"additionalProperties": false
}
},
"auctions": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"tier": { "type": "string", "format": "uuid" },
"contractTxID": { "type": "string", "format": "uuid" },
"endTimestamp": { "type": "integer" },
"startTimestamp": { "type": "integer" }
},
"required": ["tier", "contractTxID", "startTimestamp"],
"additionalProperties": false
}
},
Expand Down
1 change: 1 addition & 0 deletions src/actions/write/buyRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export const buyRecord = (
contractTxId,
tier,
type,
startTimestamp: +SmartWeave.block.timestamp,
// only include timestamp on lease
...(type === 'lease' ? { endTimestamp } : {}),
};
Expand Down
2 changes: 2 additions & 0 deletions src/actions/write/submitAuctionBid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ export const submitAuctionBid = (
contractTxId: existingAuction.contractTxId,
tier: existingAuction.tier,
type: existingAuction.type,
startTimestamp: +SmartWeave.block.timestamp,
// only include timestamp on lease
// something to think about - what if a ticking of state never comes? what do we set endTimestamp to?
...(existingAuction.type === 'lease' ? { endTimestamp } : {}),
Expand Down Expand Up @@ -330,6 +331,7 @@ export const submitAuctionBid = (
contractTxId: contractTxId, // only update the new contract tx id
tier: existingAuction.tier,
type: existingAuction.type,
startTimestamp: +SmartWeave.block.timestamp, // overwrite initial start timestamp
// only include timestamp on lease, endTimestamp is easy in this situation since it was a second interaction that won it
...(existingAuction.type === 'lease' ? { endTimestamp } : {}),
};
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export type AllowedProtocols = 'http' | 'https';

export type ArNSName = {
contractTxId: string; // The ANT Contract used to manage this name
startTimestamp: number; // At what unix time (seconds since epoch) the lease starts
endTimestamp?: number; // At what unix time (seconds since epoch) the lease ends
tier: string; // The id of the tier selected at time of purchased
type: 'lease' | 'permabuy';
Expand Down
3 changes: 3 additions & 0 deletions tests/auctions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ describe('Auctions', () => {
expect(records[auctionBid.name]).toEqual({
contractTxId: ANT_CONTRACT_IDS[1],
endTimestamp: expect.any(Number),
startTimestamp: expect.any(Number),
tier: tiers.current[0],
type: 'lease',
});
Expand Down Expand Up @@ -530,6 +531,7 @@ describe('Auctions', () => {
contractTxId: ANT_CONTRACT_IDS[1],
tier: tiers.current[0],
type: 'permabuy',
startTimestamp: expect.any(Number),
});
expect(auctions[auctionBid.name]).toBeUndefined();
expect(balances[winnerAddress]).toEqual(
Expand Down Expand Up @@ -616,6 +618,7 @@ describe('Auctions', () => {
tier: tiers.current[0],
type: 'lease',
endTimestamp: expect.any(Number),
startTimestamp: expect.any(Number),
});
const floorToBidDifference = winningBidQty - auctionObj.floorPrice;
expect(balances[nonContractOwnerAddress]).toEqual(
Expand Down
5 changes: 5 additions & 0 deletions tests/records.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('Records', () => {
tier: expectedTierObj,
name: 'name1',
endTimestamp: expect.any(Number),
startTimestamp: expect.any(Number),
contractTxID: expect.any(String),
};
expect(record).not.toBe(undefined);
Expand Down Expand Up @@ -115,6 +116,7 @@ describe('Records', () => {
contractTxId: ANT_CONTRACT_IDS[0],
tier: tiers.current[0],
endTimestamp: expect.any(Number),
startTimestamp: expect.any(Number),
type: 'lease',
});
expect(balances[nonContractOwnerAddress]).toEqual(
Expand Down Expand Up @@ -161,6 +163,7 @@ describe('Records', () => {
contractTxId: ANT_CONTRACT_IDS[0],
tier: tiers.current[0],
endTimestamp: expect.any(Number),
startTimestamp: expect.any(Number),
type: 'lease',
});
expect(balances[nonContractOwnerAddress]).toEqual(
Expand Down Expand Up @@ -207,6 +210,7 @@ describe('Records', () => {
contractTxId: ANT_CONTRACT_IDS[0],
tier: tiers.current[0],
type: 'permabuy',
startTimestamp: expect.any(Number),
});
expect(balances[nonContractOwnerAddress]).toEqual(
prevBalance - expectedPurchasePrice,
Expand Down Expand Up @@ -737,6 +741,7 @@ describe('Records', () => {
contractTxId: ANT_CONTRACT_IDS[0],
tier: tiers.current[0],
endTimestamp: expect.any(Number),
startTimestamp: expect.any(Number),
type: 'lease',
});
expect(cachedValue.errorMessages[writeInteraction!.originalTxId]).toBe(
Expand Down
1 change: 1 addition & 0 deletions tests/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function createRecords(tiers: string[], count = 3) {
tier: tiers[0],
contractTxID: ANT_CONTRACT_IDS[0],
endTimestamp: new Date('01/01/2025').getTime() / 1000,
startTimestamp: Date.now(),
};
records[name] = obj;
}
Expand Down