-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add base visitor tests for each node (#137)
* Create AccountNode.test.ts * Add test macros * Create DefinedTypeNode.test.ts * Add ErrorNode tests * Prepare all tests by copy pasting the account node tests * Update InstructionAccountNode.test.ts * Update instructionArgumentNode test * Add InstructionByteDeltaNode tests * Add instructionRemainingAccountsNode tests * Update PdaNode.test.ts * Add InstructionNode tests * Update ProgramNode.test.ts * Update RootNode.test.ts * Add tests for contextualValueNodes * Add discriminatorNodes tests * Add linkNodes tests * Add pdaSeedNodes tests * Add sizeNodes tests * Add typeNodes tests * Add valueNodes tests * Add changeset
- Loading branch information
1 parent
6d02b0e
commit d1a2149
Showing
74 changed files
with
2,158 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@metaplex-foundation/kinobi': patch | ||
--- | ||
|
||
Add base visitor tests for each node |
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,51 @@ | ||
import test from 'ava'; | ||
import { | ||
accountNode, | ||
numberTypeNode, | ||
pdaLinkNode, | ||
publicKeyTypeNode, | ||
sizeDiscriminatorNode, | ||
structFieldTypeNode, | ||
structTypeNode, | ||
} from '../../../src'; | ||
import { | ||
deleteNodesVisitorMacro, | ||
getDebugStringVisitorMacro, | ||
identityVisitorMacro, | ||
mergeVisitorMacro, | ||
} from './_setup'; | ||
|
||
const node = accountNode({ | ||
name: 'token', | ||
data: structTypeNode([ | ||
structFieldTypeNode({ name: 'mint', type: publicKeyTypeNode() }), | ||
structFieldTypeNode({ name: 'owner', type: publicKeyTypeNode() }), | ||
structFieldTypeNode({ name: 'amount', type: numberTypeNode('u64') }), | ||
]), | ||
pda: pdaLinkNode('associatedToken'), | ||
discriminators: [sizeDiscriminatorNode(72)], | ||
size: 72, | ||
}); | ||
|
||
test(mergeVisitorMacro, node, 10); | ||
test(identityVisitorMacro, node); | ||
test(deleteNodesVisitorMacro, node, '[accountNode]', null); | ||
test(deleteNodesVisitorMacro, node, '[pdaLinkNode]', { | ||
...node, | ||
pda: undefined, | ||
}); | ||
test( | ||
getDebugStringVisitorMacro, | ||
node, | ||
` | ||
accountNode [token] | ||
| structTypeNode | ||
| | structFieldTypeNode [mint] | ||
| | | publicKeyTypeNode | ||
| | structFieldTypeNode [owner] | ||
| | | publicKeyTypeNode | ||
| | structFieldTypeNode [amount] | ||
| | | numberTypeNode [u64] | ||
| pdaLinkNode [associatedToken] | ||
| sizeDiscriminatorNode [72]` | ||
); |
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,43 @@ | ||
import test from 'ava'; | ||
import { | ||
definedTypeNode, | ||
fixedSizeNode, | ||
numberTypeNode, | ||
stringTypeNode, | ||
structFieldTypeNode, | ||
structTypeNode, | ||
} from '../../../src'; | ||
import { | ||
deleteNodesVisitorMacro, | ||
getDebugStringVisitorMacro, | ||
identityVisitorMacro, | ||
mergeVisitorMacro, | ||
} from './_setup'; | ||
|
||
const node = definedTypeNode({ | ||
name: 'person', | ||
type: structTypeNode([ | ||
structFieldTypeNode({ | ||
name: 'name', | ||
type: stringTypeNode({ size: fixedSizeNode(32) }), | ||
}), | ||
structFieldTypeNode({ name: 'age', type: numberTypeNode('u64') }), | ||
]), | ||
}); | ||
|
||
test(mergeVisitorMacro, node, 7); | ||
test(identityVisitorMacro, node); | ||
test(deleteNodesVisitorMacro, node, '[definedTypeNode]', null); | ||
test(deleteNodesVisitorMacro, node, '[structTypeNode]', null); | ||
test( | ||
getDebugStringVisitorMacro, | ||
node, | ||
` | ||
definedTypeNode [person] | ||
| structTypeNode | ||
| | structFieldTypeNode [name] | ||
| | | stringTypeNode [utf8] | ||
| | | | fixedSizeNode [32] | ||
| | structFieldTypeNode [age] | ||
| | | numberTypeNode [u64]` | ||
); |
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,20 @@ | ||
import test from 'ava'; | ||
import { errorNode } from '../../../src'; | ||
import { | ||
deleteNodesVisitorMacro, | ||
getDebugStringVisitorMacro, | ||
identityVisitorMacro, | ||
mergeVisitorMacro, | ||
} from './_setup'; | ||
|
||
const node = errorNode({ | ||
name: 'InvalidTokenOwner', | ||
code: 42, | ||
message: | ||
'The provided account does not match the owner of the token account.', | ||
}); | ||
|
||
test(mergeVisitorMacro, node, 1); | ||
test(identityVisitorMacro, node); | ||
test(deleteNodesVisitorMacro, node, '[errorNode]', null); | ||
test(getDebugStringVisitorMacro, node, `errorNode [42.invalidTokenOwner]`); |
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,31 @@ | ||
import test from 'ava'; | ||
import { accountValueNode, instructionAccountNode } from '../../../src'; | ||
import { | ||
deleteNodesVisitorMacro, | ||
getDebugStringVisitorMacro, | ||
identityVisitorMacro, | ||
mergeVisitorMacro, | ||
} from './_setup'; | ||
|
||
const node = instructionAccountNode({ | ||
name: 'owner', | ||
isWritable: true, | ||
isSigner: 'either', | ||
isOptional: false, | ||
defaultValue: accountValueNode('authority'), | ||
}); | ||
|
||
test(mergeVisitorMacro, node, 2); | ||
test(identityVisitorMacro, node); | ||
test(deleteNodesVisitorMacro, node, '[instructionAccountNode]', null); | ||
test(deleteNodesVisitorMacro, node, '[accountValueNode]', { | ||
...node, | ||
defaultValue: undefined, | ||
}); | ||
test( | ||
getDebugStringVisitorMacro, | ||
node, | ||
` | ||
instructionAccountNode [owner.writable.optionalSigner] | ||
| accountValueNode [authority]` | ||
); |
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,35 @@ | ||
import test from 'ava'; | ||
import { | ||
instructionArgumentNode, | ||
numberTypeNode, | ||
numberValueNode, | ||
} from '../../../src'; | ||
import { | ||
deleteNodesVisitorMacro, | ||
getDebugStringVisitorMacro, | ||
identityVisitorMacro, | ||
mergeVisitorMacro, | ||
} from './_setup'; | ||
|
||
const node = instructionArgumentNode({ | ||
name: 'amount', | ||
type: numberTypeNode('u64'), | ||
defaultValue: numberValueNode(1), | ||
}); | ||
|
||
test(mergeVisitorMacro, node, 3); | ||
test(identityVisitorMacro, node); | ||
test(deleteNodesVisitorMacro, node, '[instructionArgumentNode]', null); | ||
test(deleteNodesVisitorMacro, node, '[numberTypeNode]', null); | ||
test(deleteNodesVisitorMacro, node, '[numberValueNode]', { | ||
...node, | ||
defaultValue: undefined, | ||
}); | ||
test( | ||
getDebugStringVisitorMacro, | ||
node, | ||
` | ||
instructionArgumentNode [amount] | ||
| numberTypeNode [u64] | ||
| numberValueNode [1]` | ||
); |
Oops, something went wrong.