|
| 1 | +import { Address } from 'ox' |
| 2 | +import { describe, expect, it } from 'vitest' |
| 3 | + |
| 4 | +import { Arweave, Reader, Sequence } from '../../../src/state/index' |
| 5 | + |
| 6 | +const tests: { [method in keyof Reader]: { [description: string]: Parameters<Reader[method]> } } = { |
| 7 | + getConfiguration: { |
| 8 | + 'image hash: 0xfd32e01d7e814292f49f57e79722ca66423833acf8f25eba770faf3483ff3e78': [ |
| 9 | + '0xfd32e01d7e814292f49f57e79722ca66423833acf8f25eba770faf3483ff3e78', |
| 10 | + ], |
| 11 | + }, |
| 12 | + getDeploy: { |
| 13 | + 'wallet: 0x47E0e44DE649B35Cf7863998Be6C5a7D5d8c63bE': ['0x47E0e44DE649B35Cf7863998Be6C5a7D5d8c63bE'], |
| 14 | + }, |
| 15 | + getWallets: { |
| 16 | + 'signer: 0x94835215CaA1aD3E304F9A7E2148623fe661dEB7': ['0x94835215CaA1aD3E304F9A7E2148623fe661dEB7'], |
| 17 | + }, |
| 18 | + getWalletsForSapient: { |
| 19 | + 'signer: 0x000000000000AB36D17eB1150116371520565205, image hash: 0xeef69774e1cb488a71f6d235c858fa564134ee7c3acda9ff116b6c9d42b3cee3': |
| 20 | + [ |
| 21 | + '0x000000000000AB36D17eB1150116371520565205', |
| 22 | + '0xeef69774e1cb488a71f6d235c858fa564134ee7c3acda9ff116b6c9d42b3cee3', |
| 23 | + ], |
| 24 | + }, |
| 25 | + getWitnessFor: { |
| 26 | + 'wallet: 0x47E0e44DE649B35Cf7863998Be6C5a7D5d8c63bE, signer: 0x94835215CaA1aD3E304F9A7E2148623fe661dEB7': [ |
| 27 | + '0x47E0e44DE649B35Cf7863998Be6C5a7D5d8c63bE', |
| 28 | + '0x94835215CaA1aD3E304F9A7E2148623fe661dEB7', |
| 29 | + ], |
| 30 | + }, |
| 31 | + getWitnessForSapient: { |
| 32 | + 'wallet: 0x47E0e44DE649B35Cf7863998Be6C5a7D5d8c63bE, signer: 0x000000000000AB36D17eB1150116371520565205, image hash: 0xeef69774e1cb488a71f6d235c858fa564134ee7c3acda9ff116b6c9d42b3cee3': |
| 33 | + [ |
| 34 | + '0x47E0e44DE649B35Cf7863998Be6C5a7D5d8c63bE', |
| 35 | + '0x000000000000AB36D17eB1150116371520565205', |
| 36 | + '0xeef69774e1cb488a71f6d235c858fa564134ee7c3acda9ff116b6c9d42b3cee3', |
| 37 | + ], |
| 38 | + }, |
| 39 | + getConfigurationUpdates: { |
| 40 | + 'wallet: 0x47E0e44DE649B35Cf7863998Be6C5a7D5d8c63bE, from: 0xfd32e01d7e814292f49f57e79722ca66423833acf8f25eba770faf3483ff3e78': |
| 41 | + [ |
| 42 | + '0x47E0e44DE649B35Cf7863998Be6C5a7D5d8c63bE', |
| 43 | + '0xfd32e01d7e814292f49f57e79722ca66423833acf8f25eba770faf3483ff3e78', |
| 44 | + ], |
| 45 | + }, |
| 46 | + getTree: { |
| 47 | + 'image hash: 0xeef69774e1cb488a71f6d235c858fa564134ee7c3acda9ff116b6c9d42b3cee3': [ |
| 48 | + '0xeef69774e1cb488a71f6d235c858fa564134ee7c3acda9ff116b6c9d42b3cee3', |
| 49 | + ], |
| 50 | + }, |
| 51 | + getPayload: { |
| 52 | + 'calls payload: 0xc78f3951686b7f16f39e25aea1fd5acc0e2177083c170b4c962be6cd45630576': [ |
| 53 | + '0xc78f3951686b7f16f39e25aea1fd5acc0e2177083c170b4c962be6cd45630576', |
| 54 | + ], |
| 55 | + 'message payload: 0x3a841ba3163a7a19cd168373df1144d38130b2f46b8d6eac956127f06fffe4f4': [ |
| 56 | + '0x3a841ba3163a7a19cd168373df1144d38130b2f46b8d6eac956127f06fffe4f4', |
| 57 | + ], |
| 58 | + 'config update payload: 0xcae631660ffa90bddc5e9b4fa9c11692a53062a61640fb958f3f2959d22fe54b': [ |
| 59 | + '0xcae631660ffa90bddc5e9b4fa9c11692a53062a61640fb958f3f2959d22fe54b', |
| 60 | + ], |
| 61 | + 'digest payload: 0xcd3c291e0939f029aaa4b4f292d5d2b2ce43baf98046d9abc2a3e8284b253432': [ |
| 62 | + '0xcd3c291e0939f029aaa4b4f292d5d2b2ce43baf98046d9abc2a3e8284b253432', |
| 63 | + ], |
| 64 | + }, |
| 65 | +} |
| 66 | + |
| 67 | +function normalize(value: any): any { |
| 68 | + switch (typeof value) { |
| 69 | + case 'string': |
| 70 | + if (Address.validate(value)) { |
| 71 | + return Address.checksum(value) |
| 72 | + } |
| 73 | + |
| 74 | + break |
| 75 | + |
| 76 | + case 'object': |
| 77 | + if (value === null) { |
| 78 | + return value |
| 79 | + } |
| 80 | + |
| 81 | + if (Array.isArray(value)) { |
| 82 | + return value.map(normalize) |
| 83 | + } |
| 84 | + |
| 85 | + return Object.fromEntries( |
| 86 | + Object.entries(value) |
| 87 | + .filter(([, value]) => value !== undefined) |
| 88 | + .map(([key, value]) => [Address.validate(key) ? Address.checksum(key) : key, normalize(value)]), |
| 89 | + ) |
| 90 | + } |
| 91 | + |
| 92 | + return value |
| 93 | +} |
| 94 | + |
| 95 | +describe('Arweave state reader', () => { |
| 96 | + const arweave = new Arweave.Reader() |
| 97 | + const sequence = new Sequence.Provider() |
| 98 | + |
| 99 | + const methods = Object.entries(tests).filter(([, methodTests]) => Object.keys(methodTests).length > 0) |
| 100 | + if (methods.length === 0) { |
| 101 | + it.skip('no configured test cases', () => {}) |
| 102 | + } |
| 103 | + |
| 104 | + for (const [method, methodTests] of methods) { |
| 105 | + describe(method, () => { |
| 106 | + for (const [description, args] of Object.entries(methodTests)) { |
| 107 | + it(description, async () => { |
| 108 | + const [actual, expected] = await Promise.all([arweave[method](...args), sequence[method](...args)]) |
| 109 | + expect(normalize(actual)).toEqual(normalize(expected)) |
| 110 | + }) |
| 111 | + } |
| 112 | + }) |
| 113 | + } |
| 114 | +}) |
0 commit comments