Skip to content

Commit

Permalink
chore(test): move unit tests next to implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Feb 4, 2025
1 parent 0cef900 commit 7e1fef1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tests/unit/ant.test.ts → src/types/ant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
AntInfoSchema,
AntStateSchema,
isAoANTState,
} from '../../src/types/ant.js';
} from './ant.js';

const stub_address = 'valid-address'.padEnd(43, '1');

Expand Down
1 change: 1 addition & 0 deletions src/types/ant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export interface AoANTWrite extends AoANTRead {
removeController: AoWriteAction<{ controller: WalletAddress }>;
/** @deprecated Use setUndernameRecord instead for undernames, and setBaseNameRecord instead for the top level name (e.g. "@") */
setRecord: AoWriteAction<AoANTSetUndernameRecordParams>;
/** @deprecated Use removeUndernameRecord instead for undernames */
removeRecord: AoWriteAction<{ undername: string }>;
setBaseNameRecord: AoWriteAction<AoANTSetBaseNameRecordParams>;
setUndernameRecord: AoWriteAction<AoANTSetUndernameRecordParams>;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/token.test.ts → src/types/token.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { strict as assert } from 'node:assert';
import { describe, it } from 'node:test';

import { ARIOToken, mARIOToken } from '../../src/types/token.js';
import { ARIOToken, mARIOToken } from './token.js';

describe('ARIOToken', () => {
it('should throw an error on invalid input', () => {
Expand Down
10 changes: 7 additions & 3 deletions tests/unit/b64.test.ts → src/utils/b64.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { strict as assert } from 'node:assert';
import { describe, it } from 'node:test';

import { fromB64Url, getRandomText, toB64Url } from '../../src/utils/base64.js';
import { fromB64Url, getRandomText, toB64Url } from './base64.js';

describe('b64utils', () => {
it('should convert various strings to base64url and back', () => {
Expand All @@ -16,8 +16,12 @@ describe('b64utils', () => {
];
for (const str of testStrings) {
const encoded = toB64Url(Buffer.from(str));
const decoded = Buffer.from(fromB64Url(encoded)).toString();
assert.strictEqual(decoded, str, `Failed for string: ${str}`);
const decoded = fromB64Url(encoded);
assert.deepStrictEqual(
decoded,
Buffer.from(str),
`Failed for string: ${str}`,
);
}
});
it('should convert various buffers to base64url and back', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/utils.test.ts → src/utils/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { strict as assert } from 'node:assert';
import { describe, it } from 'node:test';

import { pruneTags } from '../../src/utils/arweave.js';
import { errorMessageFromOutput } from '../../src/utils/index.js';
import { pruneTags } from './arweave.js';
import { errorMessageFromOutput } from './index.js';

describe('pruneTags', () => {
it('should remove tags with undefined values', () => {
Expand Down
13 changes: 11 additions & 2 deletions tests/e2e/esm/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,10 @@ describe('e2e esm tests', async () => {
assert(Array.isArray(balances.items));
balances.items.forEach((wallet) => {
assert(typeof wallet.address === 'string');
assert(typeof wallet.balance === 'number');
assert(
typeof wallet.balance === 'number',
`Balance for ${wallet.address} is not a number: ${wallet.balance}`,
);
});
});

Expand Down Expand Up @@ -1093,7 +1096,13 @@ describe('e2e esm tests', async () => {
it('should be able to get the ANT records', async () => {
const records = await ant.getRecords();
assert.ok(records);
// TODO: check enforcement of alphabetical order with '@' first
for (const record of Object.values(records)) {
assert(typeof record.transactionId === 'string');
assert(typeof record.ttlSeconds === 'number');
if (record.priority) {
assert(typeof record.priority === 'number');
}
}
});

it('should be able to get a @ record from the ANT', async () => {
Expand Down

0 comments on commit 7e1fef1

Please sign in to comment.