Skip to content

Commit

Permalink
fix(schemas): update ant schema and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
atticusofsparta committed Oct 14, 2024
1 parent 9cb2776 commit f3284ed
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
30 changes: 24 additions & 6 deletions src/types/ant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ export const ArweaveTxIdSchema = z
.refine((val) => ARWEAVE_TX_REGEX.test(val), {
message: 'Must be an Arweave Transaction ID',
});

export const IntegerStringSchema = z
.string({
description: 'Integer String',
})
.refine(
(val) => {
const num = parseInt(val);
return Number.isInteger(num) && num >= 0;
},
{ message: 'Must be a non negative integer string' },
);
export const AntRecordSchema = z.object({
transactionId: ArweaveTxIdSchema.describe('The Target ID of the undername'),
ttlSeconds: z.number(),
Expand All @@ -56,7 +68,12 @@ export const AntBalancesSchema = z.record(
export const AntStateSchema = z.object({
Name: z.string().describe('The name of the ANT.'),
Ticker: z.string().describe('The ticker symbol for the ANT.'),
Denomination: z.number(),
Denomination: z
.number()
.describe(
'The number of decimal places to use for the ANT. Defaults to 0 if not set representing whole numbers.',
)
.min(0, { message: 'Denomination must be a non-negative number' }),
Owner: ArweaveTxIdSchema.describe('The Owners address.'),
Controllers: AntControllersSchema.describe(
'Controllers of the ANT who have administrative privileges.',
Expand Down Expand Up @@ -87,12 +104,13 @@ export const AntInfoSchema = z.object({
'Transaction ID of the Source Code for the ANT.',
),
Ticker: z.string().describe('The ticker symbol for the ANT.'),
['Total-Supply']: z
.number()
.describe('Total supply of the ANT in circulation.')
.min(0, { message: 'Total supply must be a non-negative number' }),
['Total-Supply']: IntegerStringSchema.describe(
'Total supply of the ANT in circulation.',
),
Logo: ArweaveTxIdSchema.describe('Transaction ID of the ANT logo.'),
Denomination: z.number(),
Denomination: IntegerStringSchema.describe(
'The number of decimal places to use for the ANT. Defaults to 0 if not set representing whole numbers.',
),
});

export type AoANTInfo = z.infer<typeof AntInfoSchema>;
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/ant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ describe('ANT Schemas', () => {
Owner: stub_address,
['Source-Code-TX-ID']: stub_address,
Ticker: 'TST',
['Total-Supply']: 1,
['Total-Supply']: '1',
Logo: stub_address,
Denomination: 0,
Denomination: '0',
};
const invalidInfo = {
Name: 'TestToken',
Expand Down

0 comments on commit f3284ed

Please sign in to comment.