-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from ar-io/PE-6910-primary-names
feat(PE-7174): support for primary name protocol with io process
- Loading branch information
Showing
6 changed files
with
178 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { createAntAosLoader } from './utils.mjs'; | ||
import { describe, it } from 'node:test'; | ||
import assert from 'node:assert'; | ||
import { | ||
AO_LOADER_HANDLER_ENV, | ||
DEFAULT_HANDLE_OPTIONS, | ||
STUB_ADDRESS, | ||
} from '../tools/constants.mjs'; | ||
|
||
describe('Primary Names', async () => { | ||
const { handle: originalHandle, memory: startMemory } = | ||
await createAntAosLoader(); | ||
|
||
async function handle(options = {}, mem = startMemory) { | ||
return originalHandle( | ||
mem, | ||
{ | ||
...DEFAULT_HANDLE_OPTIONS, | ||
...options, | ||
}, | ||
AO_LOADER_HANDLER_ENV, | ||
); | ||
} | ||
|
||
it('should send approval for name request', async () => { | ||
const res = await handle({ | ||
Tags: [ | ||
{ | ||
name: 'Action', | ||
value: 'Approve-Primary-Name', | ||
}, | ||
{ name: 'IO-Process-Id', value: ''.padEnd(43, '1') }, | ||
{ name: 'Recipient', value: ''.padEnd(43, '2') }, | ||
{ name: 'Name', value: ''.padEnd(43, '3') }, | ||
], | ||
}); | ||
|
||
const approveNameRequest = res.Messages[0]; | ||
const actionTag = approveNameRequest.Tags.find((t) => t.name == 'Action'); | ||
const recipientTag = approveNameRequest.Tags.find( | ||
(t) => t.name == 'Recipient', | ||
); | ||
const nameTag = approveNameRequest.Tags.find((t) => t.name == 'Name'); | ||
|
||
assert.strictEqual(approveNameRequest.Target, ''.padEnd(43, '1')); | ||
assert.strictEqual(actionTag.value, 'Approve-Primary-Name-Request'); | ||
assert.strictEqual(recipientTag.value, ''.padEnd(43, '2')); | ||
assert.strictEqual(nameTag.value, ''.padEnd(43, '3')); | ||
}); | ||
|
||
it('should not approve request if caller not owner', async () => { | ||
const res = await handle({ | ||
Owner: 'not-owner'.padEnd(43, '1'), | ||
From: 'not-owner'.padEnd(43, '1'), | ||
Tags: [ | ||
{ | ||
name: 'Action', | ||
value: 'Approve-Primary-Name', | ||
}, | ||
{ name: 'IO-Process-Id', value: ''.padEnd(43, '1') }, | ||
{ name: 'Recipient', value: ''.padEnd(43, '2') }, | ||
{ name: 'Name', value: ''.padEnd(43, '3') }, | ||
], | ||
}); | ||
const invalidMessage = res.Messages[0]; | ||
const actionTag = invalidMessage.Tags.find((t) => t.name == 'Action'); | ||
assert.strictEqual(actionTag.value, 'Invalid-Approve-Primary-Name-Notice'); | ||
}); | ||
|
||
it('should send remove names request', async () => { | ||
const names = ['foo', 'bar', 'baz']; | ||
const res = await handle({ | ||
Tags: [ | ||
{ name: 'Action', value: 'Remove-Primary-Names' }, | ||
{ name: 'Names', value: names.join(',') }, | ||
{ name: 'IO-Process-Id', value: ''.padEnd(43, '2') }, | ||
], | ||
}); | ||
|
||
const removePrimaryNamesMsg = res.Messages[0]; | ||
const actionTag = removePrimaryNamesMsg.Tags.find( | ||
(t) => t.name == 'Action', | ||
); | ||
const namesTag = removePrimaryNamesMsg.Tags.find((t) => t.name == 'Names'); | ||
|
||
assert.strictEqual(removePrimaryNamesMsg.Target, ''.padEnd(43, '2')); | ||
assert.strictEqual(actionTag.value, 'Remove-Primary-Names'); | ||
assert.strictEqual(namesTag.value, JSON.stringify(names)); | ||
}); | ||
it('should not send remove names request if caller not owner', async () => { | ||
const names = ['foo', 'bar', 'baz']; | ||
const res = await handle({ | ||
Owner: 'not-owner'.padEnd(43, '1'), | ||
From: 'not-owner'.padEnd(43, '1'), | ||
Tags: [ | ||
{ name: 'Action', value: 'Remove-Primary-Names' }, | ||
{ name: 'Names', value: names.join(',') }, | ||
{ name: 'IO-Process-Id', value: ''.padEnd(43, '2') }, | ||
], | ||
}); | ||
|
||
const invalidMessage = res.Messages[0]; | ||
const actionTag = invalidMessage.Tags.find((t) => t.name == 'Action'); | ||
assert.strictEqual(actionTag.value, 'Invalid-Remove-Primary-Names-Notice'); | ||
}); | ||
}); |