|
1 | 1 | import { |
| 2 | + ArgumentValueNode, |
| 3 | + argumentValueNode, |
2 | 4 | assertIsNode, |
3 | 5 | CamelCaseString, |
| 6 | + ConstantDiscriminatorNode, |
| 7 | + constantDiscriminatorNode, |
| 8 | + constantValueNode, |
4 | 9 | instructionAccountNode, |
5 | 10 | instructionArgumentNode, |
| 11 | + instructionByteDeltaNode, |
6 | 12 | instructionNode, |
| 13 | + instructionRemainingAccountsNode, |
7 | 14 | numberTypeNode, |
| 15 | + NumberValueNode, |
8 | 16 | numberValueNode, |
9 | 17 | programNode, |
10 | 18 | rootNode, |
@@ -199,3 +207,72 @@ test('it updates the default value strategy of an instruction argument', () => { |
199 | 207 | expect(result.arguments[1].defaultValue).toEqual(numberValueNode(1)); |
200 | 208 | expect(result.arguments[1].defaultValueStrategy).toBe('optional'); |
201 | 209 | }); |
| 210 | + |
| 211 | +test('it updates the byteDeltas of an instruction', () => { |
| 212 | + // Given the following instruction node with no byteDeltas. |
| 213 | + const node = instructionNode({ |
| 214 | + name: 'myInstruction', |
| 215 | + }); |
| 216 | + |
| 217 | + // When we update the byteDeltas of that instruction. |
| 218 | + const result = visit( |
| 219 | + node, |
| 220 | + updateInstructionsVisitor({ |
| 221 | + myInstruction: { |
| 222 | + byteDeltas: [instructionByteDeltaNode(numberValueNode(100))], |
| 223 | + }, |
| 224 | + }), |
| 225 | + ); |
| 226 | + |
| 227 | + // Then we expect the following tree changes. |
| 228 | + assertIsNode(result, 'instructionNode'); |
| 229 | + expect(result.byteDeltas).toEqual([instructionByteDeltaNode(numberValueNode(100))]); |
| 230 | +}); |
| 231 | + |
| 232 | +test('it updates the discriminators of an instruction', () => { |
| 233 | + // Given the following instruction node with no discriminators. |
| 234 | + const node = instructionNode({ |
| 235 | + name: 'myInstruction', |
| 236 | + }); |
| 237 | + |
| 238 | + // When we update the discriminators of that instruction. |
| 239 | + const result = visit( |
| 240 | + node, |
| 241 | + updateInstructionsVisitor({ |
| 242 | + myInstruction: { |
| 243 | + discriminators: [ |
| 244 | + constantDiscriminatorNode(constantValueNode(numberTypeNode('u64'), numberValueNode(42))), |
| 245 | + ], |
| 246 | + }, |
| 247 | + }), |
| 248 | + ); |
| 249 | + |
| 250 | + // Then we expect the following tree changes. |
| 251 | + assertIsNode(result, 'instructionNode'); |
| 252 | + expect(result.discriminators![0].kind).toBe('constantDiscriminatorNode'); |
| 253 | + expect(((result.discriminators![0] as ConstantDiscriminatorNode).constant.value as NumberValueNode).number).toEqual( |
| 254 | + 42, |
| 255 | + ); |
| 256 | +}); |
| 257 | + |
| 258 | +test('it updates the remainingAccounts of an instruction', () => { |
| 259 | + // Given the following instruction node with no remaining accounts. |
| 260 | + const node = instructionNode({ |
| 261 | + name: 'myInstruction', |
| 262 | + }); |
| 263 | + |
| 264 | + // When we update the remaining accounts of that instruction. |
| 265 | + const result = visit( |
| 266 | + node, |
| 267 | + updateInstructionsVisitor({ |
| 268 | + myInstruction: { |
| 269 | + remainingAccounts: [instructionRemainingAccountsNode(argumentValueNode('abc'))], |
| 270 | + }, |
| 271 | + }), |
| 272 | + ); |
| 273 | + |
| 274 | + // Then we expect the following tree changes. |
| 275 | + assertIsNode(result, 'instructionNode'); |
| 276 | + expect(result.remainingAccounts![0].kind).toBe('instructionRemainingAccountsNode'); |
| 277 | + expect((result.remainingAccounts![0].value as ArgumentValueNode).name).toBe('abc'); |
| 278 | +}); |
0 commit comments