Skip to content

Commit

Permalink
chore(prettier): run prettier against repo
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Dec 10, 2023
1 parent 5be8051 commit 38d656f
Show file tree
Hide file tree
Showing 19 changed files with 59 additions and 104 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ jobs:
pull-requests: write
strategy:
matrix:
step: ['format:check', 'lint:check', 'build', 'test:unit', 'test:integration']
step:
[
'format:check',
'lint:check',
'build',
'test:unit',
'test:integration',
]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
31 changes: 11 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# ArNS - Arweave Name Token (ANT)

This repository contains the source code used for Arweave Name Tokens used to resolve ArNS names on ar-io gateways. For official documentation on ANT's refer to the [ArNS ANT Docs]. For official documentation on ArNS refer to the [ArNS Docs].
Expand All @@ -9,13 +8,10 @@ The ANT [SmartWeave] Contract is a standardized contract that contains the speci

## ANT Contract

ANT contracts need to include the following methods and match the general schema of the [ANT Contract Schema] to be usable for ArNS name resolutions.
ANT contracts need to include the following methods and match the general schema of the [ANT Contract Schema] to be usable for ArNS name resolutions.

### Methods




### `transfer`

Transfers the ownership of the ANT.
Expand All @@ -24,7 +20,6 @@ Transfers the ownership of the ANT.
| ------ | ------ | --------------------- | -------- | --------------------------- |
| target | string | "^[a-zA-Z0-9_-]{43}$" | true | Address to transfer ANT to. |


### `setRecord`

Sets a record for a given subdomain.
Expand All @@ -35,7 +30,6 @@ Sets a record for a given subdomain.
| transactionId | string | "^[a-zA-Z0-9_-]{43}$" | true | Transaction ID for the record. |
| ttlSeconds | number | Min: 900, Max: 2,592,000 | false | Time-to-live in seconds for record. |


### `setName`

Sets the name of the ANT.
Expand All @@ -44,7 +38,6 @@ Sets the name of the ANT.
| ---- | ------ | ------- | -------- | --------------------- |
| name | string | N/A | true | New name for the ANT. |


### `setTicker`

Sets the ticker symbol for the ANT.
Expand All @@ -53,7 +46,6 @@ Sets the ticker symbol for the ANT.
| ------ | ------ | ------- | -------- | -------------------------- |
| ticker | string | N/A | true | New ticker symbol for ANT. |


### `setController`

Adds a new controller to the ANT.
Expand Down Expand Up @@ -136,14 +128,13 @@ Make sure to update the variables at the top of each tool's `.ts` file, as well
- [Permaweb Cookbook]
- [Warp]

[ANT Contract Schema]:./initial-state.json
[AR.IO Gateways]:https://ar.io/docs/gateway-network/#overview
[ArNS Docs]:https://ar.io/docs/arns/
[ArNS ANT Docs]:https://ar.io/docs/arns/#arweave-name-token-ant
[ArNS Service]:https://github.com/ar-io/arns-service
[ArNS Portal]:https://arns.app
[Permaweb Cookbook]:https://cookbook.arweave.dev/concepts/arns.html
[AJV]:https://ajv.js.org/guide/getting-started.html
[Warp]:https://academy.warp.cc
[SmartWeave]:https://github.com/ArweaveTeam/SmartWeave

[ANT Contract Schema]: ./initial-state.json
[AR.IO Gateways]: https://ar.io/docs/gateway-network/#overview
[ArNS Docs]: https://ar.io/docs/arns/
[ArNS ANT Docs]: https://ar.io/docs/arns/#arweave-name-token-ant
[ArNS Service]: https://github.com/ar-io/arns-service
[ArNS Portal]: https://arns.app
[Permaweb Cookbook]: https://cookbook.arweave.dev/concepts/arns.html
[AJV]: https://ajv.js.org/guide/getting-started.html
[Warp]: https://academy.warp.cc
[SmartWeave]: https://github.com/ArweaveTeam/SmartWeave
6 changes: 3 additions & 3 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const {
setRecordSchema,
removeRecordSchema,
transferSchema,
evolveSchema
evolveSchema,
} = require('./schemas');

// build our validation source code
Expand All @@ -44,7 +44,7 @@ const ajv = new Ajv({
setRecordSchema,
removeRecordSchema,
transferSchema,
evolveSchema
evolveSchema,
],
code: { source: true, esm: true },
});
Expand All @@ -58,7 +58,7 @@ const moduleCode = standaloneCode(ajv, {
validateSetTicker: '#/definitions/setTicker',
validateBalance: '#/definitions/balance',
validateTransferTokens: '#/definitions/transfer',
validateEvolve: '#/definitions/evolve'
validateEvolve: '#/definitions/evolve',
});

// Now you can write the module code to file
Expand Down
7 changes: 5 additions & 2 deletions src/actions/write/evolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { INVALID_INPUT_MESSAGE, NON_CONTRACT_OWNER_MESSAGE } from '../../constants';
import {
INVALID_INPUT_MESSAGE,
NON_CONTRACT_OWNER_MESSAGE,
} from '../../constants';
import { ANTState, ContractResult, PstAction } from '../../types';
// composed by ajv at build
import { validateEvolve } from '../../validations';
Expand All @@ -26,7 +29,7 @@ export const evolve = async (
state: ANTState,
{ caller, input: { value } }: PstAction,
): Promise<ContractResult> => {
if (!validateEvolve({value})) {
if (!validateEvolve({ value })) {
throw new ContractError(INVALID_INPUT_MESSAGE);
}
const owner = state.owner;
Expand Down
1 change: 0 additions & 1 deletion src/actions/write/transferTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const transferTokens = async (
throw new ContractError(INVALID_INPUT_MESSAGE);
}


if (caller === target) {
throw new ContractError('Invalid token transfer');
}
Expand Down
10 changes: 5 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export type ANTRecord = {
transactionId: string,
ttlSeconds: number,
}
export type ANTRecord = {
transactionId: string;
ttlSeconds: number;
};

export type ANTState = {
ticker: string; // A short token symbol, shown in block explorers and marketplaces
name: string; // The friendly name of the token, shown in block explorers and marketplaces
owner: string; // The owner of this contract who can execute specific methods
controllers: string[]; // The controller of the records, who can add/change subdomains and their settings
records: Record<string, ANTRecord>
records: Record<string, ANTRecord>;
balances: {
// A list of all outstanding, positive, token balances
[address: string]: number;
Expand Down
4 changes: 1 addition & 3 deletions tests/evolve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,17 @@ describe('Testing evolve...', () => {
true,
);
_srcTxId = await warp.saveSource(srcTx, true);

});

it('Should evolve the ANT', async () => {
const ANT = await ANTDeployer(warp, {
address: defaultOwner[0],
wallet: defaultOwner[1],
});


const contract = warp.contract<ANTState>(ANT).connect(defaultOwner[1]);
const evolveResult = await contract.evolve(_srcTxId);

const { cachedValue } = await contract.readState();

expect(evolveResult?.originalTxId).toBeDefined();
Expand Down
2 changes: 0 additions & 2 deletions tests/removeController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ describe('Testing removeController...', () => {
address: defaultOwner[0],
wallet: defaultOwner[1],
});


const contract = warp.contract<ANTState>(ANT).connect(defaultOwner[1]);
const result = await contract.writeInteraction({
Expand All @@ -42,7 +41,6 @@ describe('Testing removeController...', () => {
expect(result).toBeDefined();
expect(result?.originalTxId).toBeDefined();


const { cachedValue } = await contract.readState();
const state = cachedValue.state;
expect(state.controllers).not.toContain(defaultOwner[0]);
Expand Down
13 changes: 2 additions & 11 deletions tests/removeRecord.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ describe('Testing removeRecord...', () => {
address: defaultOwner[0],
wallet: defaultOwner[1],
});


const contract = warp.contract<ANTState>(ANT).connect(defaultOwner[1]);
const subDomain = 'test';
Expand All @@ -48,8 +47,6 @@ describe('Testing removeRecord...', () => {
expect(setResult).toBeDefined();
expect(setResult?.originalTxId).toBeDefined();



const result = await contract.writeInteraction({
function: 'removeRecord',
subDomain,
Expand All @@ -58,7 +55,6 @@ describe('Testing removeRecord...', () => {
expect(result).toBeDefined();
expect(result?.originalTxId).toBeDefined();


const { cachedValue } = await contract.readState();
const state = cachedValue.state;
expect(Object.keys(state.records)).not.toContain(subDomain);
Expand All @@ -69,7 +65,6 @@ describe('Testing removeRecord...', () => {
address: defaultOwner[0],
wallet: defaultOwner[1],
});


const contract = warp.contract<ANTState>(ANT).connect(defaultOwner[1]);
await contract.writeInteraction({
Expand All @@ -78,14 +73,13 @@ describe('Testing removeRecord...', () => {
transactionId: defaultOwner[0],
ttlSeconds: MIN_TTL_LENGTH,
});


contract.connect(defaultOwner2[1]);
await contract.writeInteraction({
function: 'removeRecord',
subDomain: 'test',
});

const { cachedValue: newCachedValue } = await contract.readState();
const newState = newCachedValue.state as ANTState;
expect(newState.records['test']).not.toEqual(undefined);
Expand All @@ -100,15 +94,13 @@ describe('Testing removeRecord...', () => {
address: defaultOwner[0],
wallet: defaultOwner[1],
});


const contract = warp.contract<ANTState>(ANT).connect(defaultOwner[1]);

await contract.writeInteraction({
function: 'setController',
target: defaultOwner2[0],
});


contract.connect(defaultOwner2[1]);
await contract.writeInteraction({
Expand All @@ -117,13 +109,12 @@ describe('Testing removeRecord...', () => {
transactionId,
ttlSeconds,
});


await contract.writeInteraction({
function: 'removeRecord',
subDomain,
});

const { cachedValue: newCachedValue } = await contract.readState();
const newState = newCachedValue.state as ANTState;
expect(newState.records[subDomain]).toEqual(undefined);
Expand Down
5 changes: 1 addition & 4 deletions tests/setController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ describe('Testing setController...', () => {
address: defaultOwner[0],
wallet: defaultOwner[1],
});


const contract = warp.contract<ANTState>(ANT).connect(defaultOwner[1]);

Expand All @@ -44,7 +43,6 @@ describe('Testing setController...', () => {
expect(result).toBeDefined();
expect(result?.originalTxId).toBeDefined();


const { cachedValue } = await contract.readState();
const state = cachedValue.state;
expect(state.controllers).toContain(defaultOwner2[0]);
Expand All @@ -55,7 +53,6 @@ describe('Testing setController...', () => {
address: defaultOwner[0],
wallet: defaultOwner[1],
});


const contract = warp.contract<ANTState>(ANT).connect(defaultOwner2[1]);

Expand All @@ -65,7 +62,7 @@ describe('Testing setController...', () => {
function: 'setController',
target: 'HACKED',
});

expect(writeInteraction?.originalTxId).not.toBe(undefined);
const { cachedValue: newCachedValue } = await contract.readState();
const newState = newCachedValue.state as ANTState;
Expand Down
10 changes: 3 additions & 7 deletions tests/setName.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ describe('Testing setName...', () => {
address: defaultOwner[0],
wallet: defaultOwner[1],
});


const contract = warp.contract<ANTState>(ANT).connect(defaultOwner[1]);

Expand All @@ -46,7 +45,6 @@ describe('Testing setName...', () => {
expect(result).toBeDefined();
expect(result?.originalTxId).toBeDefined();


const { cachedValue } = await contract.readState();
const state = cachedValue.state;
expect(state.name).toEqual(name);
Expand All @@ -57,7 +55,6 @@ describe('Testing setName...', () => {
address: defaultOwner[0],
wallet: defaultOwner[1],
});


const contract = warp.contract<ANTState>(ANT).connect(defaultOwner2[1]);
const { cachedValue: prevCachedValue } = await contract.readState();
Expand All @@ -66,7 +63,7 @@ describe('Testing setName...', () => {
function: 'setName',
name: 'HACKED',
});

expect(writeInteraction?.originalTxId).not.toBe(undefined);
const { cachedValue: newCachedValue } = await contract.readState();
const newState = newCachedValue.state as ANTState;
Expand All @@ -78,21 +75,20 @@ describe('Testing setName...', () => {
address: defaultOwner[0],
wallet: defaultOwner[1],
});


const contract = warp.contract<ANTState>(ANT).connect(defaultOwner[1]);

await contract.writeInteraction({
function: 'setController',
target: defaultOwner2[0],
});

contract.connect(defaultOwner2[1]);
await contract.writeInteraction({
function: 'setName',
name: 'My New Token Renamed',
});

const { cachedValue: newCachedValue } = await contract.readState();
const newState = newCachedValue.state as ANTState;
expect(newState.name).toEqual('My New Token Renamed');
Expand Down
Loading

0 comments on commit 38d656f

Please sign in to comment.