@0xsequence/catapult 1.3.16 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +250 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +1 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/list.d.ts.map +1 -1
- package/dist/commands/list.js +12 -0
- package/dist/commands/list.js.map +1 -1
- package/dist/commands/provenance.d.ts +3 -0
- package/dist/commands/provenance.d.ts.map +1 -0
- package/dist/commands/provenance.js +138 -0
- package/dist/commands/provenance.js.map +1 -0
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +7 -4
- package/dist/commands/run.js.map +1 -1
- package/dist/lib/__tests__/deployer.spec.js +118 -1
- package/dist/lib/__tests__/deployer.spec.js.map +1 -1
- package/dist/lib/__tests__/network-utils.spec.js +53 -8
- package/dist/lib/__tests__/network-utils.spec.js.map +1 -1
- package/dist/lib/__tests__/provenance.spec.d.ts +2 -0
- package/dist/lib/__tests__/provenance.spec.d.ts.map +1 -0
- package/dist/lib/__tests__/provenance.spec.js +205 -0
- package/dist/lib/__tests__/provenance.spec.js.map +1 -0
- package/dist/lib/contracts/__tests__/repository.spec.js +243 -0
- package/dist/lib/contracts/__tests__/repository.spec.js.map +1 -1
- package/dist/lib/contracts/repository.d.ts +9 -1
- package/dist/lib/contracts/repository.d.ts.map +1 -1
- package/dist/lib/contracts/repository.js +93 -7
- package/dist/lib/contracts/repository.js.map +1 -1
- package/dist/lib/core/__tests__/assert-action.spec.d.ts +2 -0
- package/dist/lib/core/__tests__/assert-action.spec.d.ts.map +1 -0
- package/dist/lib/core/__tests__/assert-action.spec.js +377 -0
- package/dist/lib/core/__tests__/assert-action.spec.js.map +1 -0
- package/dist/lib/core/__tests__/engine.spec.js +80 -0
- package/dist/lib/core/__tests__/engine.spec.js.map +1 -1
- package/dist/lib/core/__tests__/loader.spec.js +29 -0
- package/dist/lib/core/__tests__/loader.spec.js.map +1 -1
- package/dist/lib/core/__tests__/resolver.spec.js +383 -0
- package/dist/lib/core/__tests__/resolver.spec.js.map +1 -1
- package/dist/lib/core/engine.d.ts.map +1 -1
- package/dist/lib/core/engine.js +33 -0
- package/dist/lib/core/engine.js.map +1 -1
- package/dist/lib/core/loader.d.ts +1 -0
- package/dist/lib/core/loader.d.ts.map +1 -1
- package/dist/lib/core/loader.js +6 -1
- package/dist/lib/core/loader.js.map +1 -1
- package/dist/lib/core/resolver.d.ts +2 -0
- package/dist/lib/core/resolver.d.ts.map +1 -1
- package/dist/lib/core/resolver.js +89 -0
- package/dist/lib/core/resolver.js.map +1 -1
- package/dist/lib/deployer.d.ts.map +1 -1
- package/dist/lib/deployer.js +21 -4
- package/dist/lib/deployer.js.map +1 -1
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +1 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/parsers/__tests__/job.spec.js +77 -0
- package/dist/lib/parsers/__tests__/job.spec.js.map +1 -1
- package/dist/lib/parsers/__tests__/source.spec.d.ts +2 -0
- package/dist/lib/parsers/__tests__/source.spec.d.ts.map +1 -0
- package/dist/lib/parsers/__tests__/source.spec.js +121 -0
- package/dist/lib/parsers/__tests__/source.spec.js.map +1 -0
- package/dist/lib/parsers/index.d.ts +1 -0
- package/dist/lib/parsers/index.d.ts.map +1 -1
- package/dist/lib/parsers/index.js +1 -0
- package/dist/lib/parsers/index.js.map +1 -1
- package/dist/lib/parsers/job.d.ts.map +1 -1
- package/dist/lib/parsers/job.js +11 -0
- package/dist/lib/parsers/job.js.map +1 -1
- package/dist/lib/parsers/source.d.ts +4 -0
- package/dist/lib/parsers/source.d.ts.map +1 -0
- package/dist/lib/parsers/source.js +107 -0
- package/dist/lib/parsers/source.js.map +1 -0
- package/dist/lib/provenance.d.ts +34 -0
- package/dist/lib/provenance.d.ts.map +1 -0
- package/dist/lib/provenance.js +645 -0
- package/dist/lib/provenance.js.map +1 -0
- package/dist/lib/types/actions.d.ts +18 -2
- package/dist/lib/types/actions.d.ts.map +1 -1
- package/dist/lib/types/actions.js +1 -0
- package/dist/lib/types/actions.js.map +1 -1
- package/dist/lib/types/contracts.d.ts +3 -0
- package/dist/lib/types/contracts.d.ts.map +1 -1
- package/dist/lib/types/definitions.d.ts +1 -0
- package/dist/lib/types/definitions.d.ts.map +1 -1
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/index.d.ts.map +1 -1
- package/dist/lib/types/index.js +1 -0
- package/dist/lib/types/index.js.map +1 -1
- package/dist/lib/types/source.d.ts +24 -0
- package/dist/lib/types/source.d.ts.map +1 -0
- package/dist/lib/types/source.js +3 -0
- package/dist/lib/types/source.js.map +1 -0
- package/dist/lib/types/values.d.ts +33 -1
- package/dist/lib/types/values.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cli.ts +3 -2
- package/src/commands/index.ts +2 -1
- package/src/commands/list.ts +14 -1
- package/src/commands/provenance.ts +120 -0
- package/src/commands/run.ts +11 -6
- package/src/lib/__tests__/deployer.spec.ts +177 -1
- package/src/lib/__tests__/network-utils.spec.ts +63 -14
- package/src/lib/__tests__/provenance.spec.ts +208 -0
- package/src/lib/contracts/__tests__/repository.spec.ts +270 -2
- package/src/lib/contracts/repository.ts +112 -14
- package/src/lib/core/__tests__/assert-action.spec.ts +474 -0
- package/src/lib/core/__tests__/engine.spec.ts +116 -0
- package/src/lib/core/__tests__/loader.spec.ts +34 -1
- package/src/lib/core/__tests__/resolver.spec.ts +444 -1
- package/src/lib/core/engine.ts +52 -0
- package/src/lib/core/loader.ts +8 -2
- package/src/lib/core/resolver.ts +116 -0
- package/src/lib/deployer.ts +28 -4
- package/src/lib/index.ts +4 -1
- package/src/lib/parsers/__tests__/job.spec.ts +81 -0
- package/src/lib/parsers/__tests__/source.spec.ts +134 -0
- package/src/lib/parsers/index.ts +1 -0
- package/src/lib/parsers/job.ts +14 -2
- package/src/lib/parsers/source.ts +129 -0
- package/src/lib/provenance.ts +785 -0
- package/src/lib/types/actions.ts +22 -1
- package/src/lib/types/contracts.ts +4 -1
- package/src/lib/types/definitions.ts +7 -0
- package/src/lib/types/index.ts +1 -0
- package/src/lib/types/source.ts +26 -0
- package/src/lib/types/values.ts +71 -0
|
@@ -1678,5 +1678,388 @@ describe('ValueResolver', () => {
|
|
|
1678
1678
|
expect(result).toBe('0x010203');
|
|
1679
1679
|
});
|
|
1680
1680
|
});
|
|
1681
|
+
describe('get-storage-at', () => {
|
|
1682
|
+
const testAddress = '0x1234567890123456789012345678901234567890';
|
|
1683
|
+
const testSlot = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
1684
|
+
const testSlotNumber = 0;
|
|
1685
|
+
const expectedStorageValue = '0x0000000000000000000000000000000000000000000000000000000000000001';
|
|
1686
|
+
let anvilProvider;
|
|
1687
|
+
beforeEach(async () => {
|
|
1688
|
+
anvilProvider = context.provider;
|
|
1689
|
+
});
|
|
1690
|
+
it('should read storage slot with hex string slot', async () => {
|
|
1691
|
+
await anvilProvider.send('anvil_setStorageAt', [testAddress, testSlot, expectedStorageValue]);
|
|
1692
|
+
const value = {
|
|
1693
|
+
type: 'get-storage-at',
|
|
1694
|
+
arguments: {
|
|
1695
|
+
address: testAddress,
|
|
1696
|
+
slot: testSlot
|
|
1697
|
+
},
|
|
1698
|
+
};
|
|
1699
|
+
const result = await resolver.resolve(value, context);
|
|
1700
|
+
expect(result).toBe(expectedStorageValue);
|
|
1701
|
+
});
|
|
1702
|
+
it('should read storage slot with numeric slot', async () => {
|
|
1703
|
+
await anvilProvider.send('anvil_setStorageAt', [testAddress, testSlot, expectedStorageValue]);
|
|
1704
|
+
const value = {
|
|
1705
|
+
type: 'get-storage-at',
|
|
1706
|
+
arguments: {
|
|
1707
|
+
address: testAddress,
|
|
1708
|
+
slot: testSlotNumber
|
|
1709
|
+
},
|
|
1710
|
+
};
|
|
1711
|
+
const result = await resolver.resolve(value, context);
|
|
1712
|
+
expect(result).toBe(expectedStorageValue);
|
|
1713
|
+
});
|
|
1714
|
+
it('should read storage slot with string number slot', async () => {
|
|
1715
|
+
await anvilProvider.send('anvil_setStorageAt', [testAddress, testSlot, expectedStorageValue]);
|
|
1716
|
+
const value = {
|
|
1717
|
+
type: 'get-storage-at',
|
|
1718
|
+
arguments: {
|
|
1719
|
+
address: testAddress,
|
|
1720
|
+
slot: '0'
|
|
1721
|
+
},
|
|
1722
|
+
};
|
|
1723
|
+
const result = await resolver.resolve(value, context);
|
|
1724
|
+
expect(result).toBe(expectedStorageValue);
|
|
1725
|
+
});
|
|
1726
|
+
it('should read different storage slots', async () => {
|
|
1727
|
+
const slot1 = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
1728
|
+
const slot2 = '0x0000000000000000000000000000000000000000000000000000000000000001';
|
|
1729
|
+
const value1 = '0x00000000000000000000000000000000000000000000000000000000000000aa';
|
|
1730
|
+
const value2 = '0x00000000000000000000000000000000000000000000000000000000000000bb';
|
|
1731
|
+
await anvilProvider.send('anvil_setStorageAt', [testAddress, slot1, value1]);
|
|
1732
|
+
await anvilProvider.send('anvil_setStorageAt', [testAddress, slot2, value2]);
|
|
1733
|
+
const valueForSlot1 = {
|
|
1734
|
+
type: 'get-storage-at',
|
|
1735
|
+
arguments: {
|
|
1736
|
+
address: testAddress,
|
|
1737
|
+
slot: slot1
|
|
1738
|
+
},
|
|
1739
|
+
};
|
|
1740
|
+
const valueForSlot2 = {
|
|
1741
|
+
type: 'get-storage-at',
|
|
1742
|
+
arguments: {
|
|
1743
|
+
address: testAddress,
|
|
1744
|
+
slot: slot2
|
|
1745
|
+
},
|
|
1746
|
+
};
|
|
1747
|
+
const result1 = await resolver.resolve(valueForSlot1, context);
|
|
1748
|
+
const result2 = await resolver.resolve(valueForSlot2, context);
|
|
1749
|
+
expect(result1).toBe(value1);
|
|
1750
|
+
expect(result2).toBe(value2);
|
|
1751
|
+
});
|
|
1752
|
+
it('should resolve address from context variable', async () => {
|
|
1753
|
+
context.setOutput('myAddress', testAddress);
|
|
1754
|
+
await anvilProvider.send('anvil_setStorageAt', [testAddress, testSlot, expectedStorageValue]);
|
|
1755
|
+
const value = {
|
|
1756
|
+
type: 'get-storage-at',
|
|
1757
|
+
arguments: {
|
|
1758
|
+
address: '{{myAddress}}',
|
|
1759
|
+
slot: testSlot
|
|
1760
|
+
},
|
|
1761
|
+
};
|
|
1762
|
+
const result = await resolver.resolve(value, context);
|
|
1763
|
+
expect(result).toBe(expectedStorageValue);
|
|
1764
|
+
});
|
|
1765
|
+
it('should resolve slot from context variable', async () => {
|
|
1766
|
+
context.setOutput('mySlot', testSlot);
|
|
1767
|
+
await anvilProvider.send('anvil_setStorageAt', [testAddress, testSlot, expectedStorageValue]);
|
|
1768
|
+
const value = {
|
|
1769
|
+
type: 'get-storage-at',
|
|
1770
|
+
arguments: {
|
|
1771
|
+
address: testAddress,
|
|
1772
|
+
slot: '{{mySlot}}'
|
|
1773
|
+
},
|
|
1774
|
+
};
|
|
1775
|
+
const result = await resolver.resolve(value, context);
|
|
1776
|
+
expect(result).toBe(expectedStorageValue);
|
|
1777
|
+
});
|
|
1778
|
+
it('should return zero storage for non-existent slot', async () => {
|
|
1779
|
+
const nonExistentSlot = '0x000000000000000000000000000000000000000000000000000000000000ffff';
|
|
1780
|
+
const value = {
|
|
1781
|
+
type: 'get-storage-at',
|
|
1782
|
+
arguments: {
|
|
1783
|
+
address: testAddress,
|
|
1784
|
+
slot: nonExistentSlot
|
|
1785
|
+
},
|
|
1786
|
+
};
|
|
1787
|
+
const result = await resolver.resolve(value, context);
|
|
1788
|
+
expect(result).toBe('0x0000000000000000000000000000000000000000000000000000000000000000');
|
|
1789
|
+
});
|
|
1790
|
+
it('should throw error for invalid address', async () => {
|
|
1791
|
+
const value = {
|
|
1792
|
+
type: 'get-storage-at',
|
|
1793
|
+
arguments: {
|
|
1794
|
+
address: 'invalid-address',
|
|
1795
|
+
slot: testSlot
|
|
1796
|
+
},
|
|
1797
|
+
};
|
|
1798
|
+
await expect(resolver.resolve(value, context)).rejects.toThrow('Invalid address: invalid-address');
|
|
1799
|
+
});
|
|
1800
|
+
it('should throw error for null address', async () => {
|
|
1801
|
+
const value = {
|
|
1802
|
+
type: 'get-storage-at',
|
|
1803
|
+
arguments: {
|
|
1804
|
+
address: null,
|
|
1805
|
+
slot: testSlot
|
|
1806
|
+
},
|
|
1807
|
+
};
|
|
1808
|
+
await expect(resolver.resolve(value, context)).rejects.toThrow('Invalid address: null');
|
|
1809
|
+
});
|
|
1810
|
+
it('should throw error for undefined address', async () => {
|
|
1811
|
+
const value = {
|
|
1812
|
+
type: 'get-storage-at',
|
|
1813
|
+
arguments: {
|
|
1814
|
+
address: undefined,
|
|
1815
|
+
slot: testSlot
|
|
1816
|
+
},
|
|
1817
|
+
};
|
|
1818
|
+
await expect(resolver.resolve(value, context)).rejects.toThrow('Invalid address: undefined');
|
|
1819
|
+
});
|
|
1820
|
+
it('should handle checksummed addresses', async () => {
|
|
1821
|
+
const checksummedAddress = '0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed';
|
|
1822
|
+
await anvilProvider.send('anvil_setStorageAt', [checksummedAddress, testSlot, expectedStorageValue]);
|
|
1823
|
+
const value = {
|
|
1824
|
+
type: 'get-storage-at',
|
|
1825
|
+
arguments: {
|
|
1826
|
+
address: checksummedAddress,
|
|
1827
|
+
slot: testSlot
|
|
1828
|
+
},
|
|
1829
|
+
};
|
|
1830
|
+
const result = await resolver.resolve(value, context);
|
|
1831
|
+
expect(result).toBe(expectedStorageValue);
|
|
1832
|
+
});
|
|
1833
|
+
it('should handle lowercase addresses', async () => {
|
|
1834
|
+
const lowercaseAddress = testAddress.toLowerCase();
|
|
1835
|
+
await anvilProvider.send('anvil_setStorageAt', [lowercaseAddress, testSlot, expectedStorageValue]);
|
|
1836
|
+
const value = {
|
|
1837
|
+
type: 'get-storage-at',
|
|
1838
|
+
arguments: {
|
|
1839
|
+
address: lowercaseAddress,
|
|
1840
|
+
slot: testSlot
|
|
1841
|
+
},
|
|
1842
|
+
};
|
|
1843
|
+
const result = await resolver.resolve(value, context);
|
|
1844
|
+
expect(result).toBe(expectedStorageValue);
|
|
1845
|
+
});
|
|
1846
|
+
it('should handle large slot numbers', async () => {
|
|
1847
|
+
const eip1967Slot = '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc';
|
|
1848
|
+
await anvilProvider.send('anvil_setStorageAt', [testAddress, eip1967Slot, expectedStorageValue]);
|
|
1849
|
+
const value = {
|
|
1850
|
+
type: 'get-storage-at',
|
|
1851
|
+
arguments: {
|
|
1852
|
+
address: testAddress,
|
|
1853
|
+
slot: eip1967Slot
|
|
1854
|
+
},
|
|
1855
|
+
};
|
|
1856
|
+
const result = await resolver.resolve(value, context);
|
|
1857
|
+
expect(result).toBe(expectedStorageValue);
|
|
1858
|
+
});
|
|
1859
|
+
});
|
|
1860
|
+
describe('compute-slot', () => {
|
|
1861
|
+
describe('mapping', () => {
|
|
1862
|
+
it('should compute a mapping value slot with an address key', async () => {
|
|
1863
|
+
const value = {
|
|
1864
|
+
type: 'compute-slot',
|
|
1865
|
+
arguments: {
|
|
1866
|
+
kind: 'mapping',
|
|
1867
|
+
slot: 2,
|
|
1868
|
+
key: '0x1111111111111111111111111111111111111111',
|
|
1869
|
+
keyType: 'address',
|
|
1870
|
+
},
|
|
1871
|
+
};
|
|
1872
|
+
const result = await resolver.resolve(value, context);
|
|
1873
|
+
expect(result).toBe('0x06bb1b9bc4293ba066a12274418b7ea4df183c2e4e6b39591987369520ca3956');
|
|
1874
|
+
});
|
|
1875
|
+
it('should default keyType to uint256', async () => {
|
|
1876
|
+
const value = {
|
|
1877
|
+
type: 'compute-slot',
|
|
1878
|
+
arguments: {
|
|
1879
|
+
kind: 'mapping',
|
|
1880
|
+
slot: 1,
|
|
1881
|
+
key: 5,
|
|
1882
|
+
},
|
|
1883
|
+
};
|
|
1884
|
+
const result = await resolver.resolve(value, context);
|
|
1885
|
+
expect(result).toBe('0xe2689cd4a84e23ad2f564004f1c9013e9589d260bde6380aba3ca7e09e4df40c');
|
|
1886
|
+
});
|
|
1887
|
+
it('should pack dynamic (string) keys', async () => {
|
|
1888
|
+
const value = {
|
|
1889
|
+
type: 'compute-slot',
|
|
1890
|
+
arguments: {
|
|
1891
|
+
kind: 'mapping',
|
|
1892
|
+
slot: 7,
|
|
1893
|
+
key: 'hello',
|
|
1894
|
+
keyType: 'string',
|
|
1895
|
+
},
|
|
1896
|
+
};
|
|
1897
|
+
const result = await resolver.resolve(value, context);
|
|
1898
|
+
expect(result).toBe('0xa39e328cf6237afe41b514c6c18ccdc6b503f43ce841d4b5bca5e763723b44a9');
|
|
1899
|
+
});
|
|
1900
|
+
it('should support nesting for nested mappings', async () => {
|
|
1901
|
+
const value = {
|
|
1902
|
+
type: 'compute-slot',
|
|
1903
|
+
arguments: {
|
|
1904
|
+
kind: 'mapping',
|
|
1905
|
+
key: '0x2222222222222222222222222222222222222222',
|
|
1906
|
+
keyType: 'address',
|
|
1907
|
+
slot: {
|
|
1908
|
+
type: 'compute-slot',
|
|
1909
|
+
arguments: {
|
|
1910
|
+
kind: 'mapping',
|
|
1911
|
+
slot: 0,
|
|
1912
|
+
key: '0x1111111111111111111111111111111111111111',
|
|
1913
|
+
keyType: 'address',
|
|
1914
|
+
},
|
|
1915
|
+
},
|
|
1916
|
+
},
|
|
1917
|
+
};
|
|
1918
|
+
const result = await resolver.resolve(value, context);
|
|
1919
|
+
expect(result).toBe('0xd1360c905f62126f789549525bc3219e0fb5feba645fd0705768a3cc3bf3fc5c');
|
|
1920
|
+
});
|
|
1921
|
+
it('should resolve references in arguments', async () => {
|
|
1922
|
+
context.setOutput('mapSlot', 2);
|
|
1923
|
+
context.setOutput('owner', '0x1111111111111111111111111111111111111111');
|
|
1924
|
+
const value = {
|
|
1925
|
+
type: 'compute-slot',
|
|
1926
|
+
arguments: {
|
|
1927
|
+
kind: 'mapping',
|
|
1928
|
+
slot: '{{mapSlot}}',
|
|
1929
|
+
key: '{{owner}}',
|
|
1930
|
+
keyType: 'address',
|
|
1931
|
+
},
|
|
1932
|
+
};
|
|
1933
|
+
const result = await resolver.resolve(value, context);
|
|
1934
|
+
expect(result).toBe('0x06bb1b9bc4293ba066a12274418b7ea4df183c2e4e6b39591987369520ca3956');
|
|
1935
|
+
});
|
|
1936
|
+
it('should throw when key is missing', async () => {
|
|
1937
|
+
const value = {
|
|
1938
|
+
type: 'compute-slot',
|
|
1939
|
+
arguments: { kind: 'mapping', slot: 0 },
|
|
1940
|
+
};
|
|
1941
|
+
await expect(resolver.resolve(value, context)).rejects.toThrow('compute-slot (mapping): "key" is required');
|
|
1942
|
+
});
|
|
1943
|
+
});
|
|
1944
|
+
describe('dynamic-array', () => {
|
|
1945
|
+
it('should compute an element slot', async () => {
|
|
1946
|
+
const value = {
|
|
1947
|
+
type: 'compute-slot',
|
|
1948
|
+
arguments: { kind: 'dynamic-array', slot: 3, index: 4 },
|
|
1949
|
+
};
|
|
1950
|
+
const result = await resolver.resolve(value, context);
|
|
1951
|
+
expect(result).toBe('0xc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85f');
|
|
1952
|
+
});
|
|
1953
|
+
it('should default index to 0', async () => {
|
|
1954
|
+
const value = {
|
|
1955
|
+
type: 'compute-slot',
|
|
1956
|
+
arguments: { kind: 'dynamic-array', slot: 3 },
|
|
1957
|
+
};
|
|
1958
|
+
const result = await resolver.resolve(value, context);
|
|
1959
|
+
expect(result).toBe(ethers_1.ethers.keccak256(ethers_1.ethers.toBeHex(3, 32)));
|
|
1960
|
+
});
|
|
1961
|
+
it('should account for multi-slot elements via elementSize', async () => {
|
|
1962
|
+
const value = {
|
|
1963
|
+
type: 'compute-slot',
|
|
1964
|
+
arguments: { kind: 'dynamic-array', slot: 3, index: 1, elementSize: 2 },
|
|
1965
|
+
};
|
|
1966
|
+
const result = await resolver.resolve(value, context);
|
|
1967
|
+
expect(result).toBe('0xc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85d');
|
|
1968
|
+
});
|
|
1969
|
+
});
|
|
1970
|
+
describe('struct-field', () => {
|
|
1971
|
+
it('should add the field offset to the base slot', async () => {
|
|
1972
|
+
const value = {
|
|
1973
|
+
type: 'compute-slot',
|
|
1974
|
+
arguments: { kind: 'struct-field', slot: 100, offset: 3 },
|
|
1975
|
+
};
|
|
1976
|
+
const result = await resolver.resolve(value, context);
|
|
1977
|
+
expect(result).toBe('0x0000000000000000000000000000000000000000000000000000000000000067');
|
|
1978
|
+
});
|
|
1979
|
+
it('should throw when offset is missing', async () => {
|
|
1980
|
+
const value = {
|
|
1981
|
+
type: 'compute-slot',
|
|
1982
|
+
arguments: { kind: 'struct-field', slot: 1 },
|
|
1983
|
+
};
|
|
1984
|
+
await expect(resolver.resolve(value, context)).rejects.toThrow('compute-slot (struct-field): "offset" is required');
|
|
1985
|
+
});
|
|
1986
|
+
});
|
|
1987
|
+
describe('erc7201', () => {
|
|
1988
|
+
it('should compute the namespaced root for the EIP-7201 example', async () => {
|
|
1989
|
+
const value = {
|
|
1990
|
+
type: 'compute-slot',
|
|
1991
|
+
arguments: { kind: 'erc7201', id: 'example.main' },
|
|
1992
|
+
};
|
|
1993
|
+
const result = await resolver.resolve(value, context);
|
|
1994
|
+
expect(result).toBe('0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500');
|
|
1995
|
+
});
|
|
1996
|
+
it('should match OpenZeppelin Ownable namespace', async () => {
|
|
1997
|
+
const value = {
|
|
1998
|
+
type: 'compute-slot',
|
|
1999
|
+
arguments: { kind: 'erc7201', id: 'openzeppelin.storage.Ownable' },
|
|
2000
|
+
};
|
|
2001
|
+
const result = await resolver.resolve(value, context);
|
|
2002
|
+
expect(result).toBe('0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300');
|
|
2003
|
+
});
|
|
2004
|
+
it('should throw on empty id', async () => {
|
|
2005
|
+
const value = {
|
|
2006
|
+
type: 'compute-slot',
|
|
2007
|
+
arguments: { kind: 'erc7201', id: '' },
|
|
2008
|
+
};
|
|
2009
|
+
await expect(resolver.resolve(value, context)).rejects.toThrow('compute-slot (erc7201): "id" must be a non-empty string');
|
|
2010
|
+
});
|
|
2011
|
+
});
|
|
2012
|
+
describe('eip1967', () => {
|
|
2013
|
+
it('should compute the implementation slot', async () => {
|
|
2014
|
+
const value = {
|
|
2015
|
+
type: 'compute-slot',
|
|
2016
|
+
arguments: { kind: 'eip1967', name: 'implementation' },
|
|
2017
|
+
};
|
|
2018
|
+
const result = await resolver.resolve(value, context);
|
|
2019
|
+
expect(result).toBe('0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc');
|
|
2020
|
+
});
|
|
2021
|
+
it('should compute the admin slot', async () => {
|
|
2022
|
+
const value = {
|
|
2023
|
+
type: 'compute-slot',
|
|
2024
|
+
arguments: { kind: 'eip1967', name: 'admin' },
|
|
2025
|
+
};
|
|
2026
|
+
const result = await resolver.resolve(value, context);
|
|
2027
|
+
expect(result).toBe('0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103');
|
|
2028
|
+
});
|
|
2029
|
+
it('should compute the beacon slot', async () => {
|
|
2030
|
+
const value = {
|
|
2031
|
+
type: 'compute-slot',
|
|
2032
|
+
arguments: { kind: 'eip1967', name: 'beacon' },
|
|
2033
|
+
};
|
|
2034
|
+
const result = await resolver.resolve(value, context);
|
|
2035
|
+
expect(result).toBe('0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50');
|
|
2036
|
+
});
|
|
2037
|
+
it('should throw on unknown name', async () => {
|
|
2038
|
+
const value = {
|
|
2039
|
+
type: 'compute-slot',
|
|
2040
|
+
arguments: { kind: 'eip1967', name: 'nope' },
|
|
2041
|
+
};
|
|
2042
|
+
await expect(resolver.resolve(value, context)).rejects.toThrow('compute-slot (eip1967): "name" must be one of');
|
|
2043
|
+
});
|
|
2044
|
+
});
|
|
2045
|
+
it('should chain into get-storage-at as the slot argument', async () => {
|
|
2046
|
+
const computed = await resolver.resolve({
|
|
2047
|
+
type: 'compute-slot',
|
|
2048
|
+
arguments: { kind: 'eip1967', name: 'implementation' },
|
|
2049
|
+
}, context);
|
|
2050
|
+
expect(computed).toBe('0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc');
|
|
2051
|
+
});
|
|
2052
|
+
it('should throw when kind is missing', async () => {
|
|
2053
|
+
const value = { type: 'compute-slot', arguments: {} };
|
|
2054
|
+
await expect(resolver.resolve(value, context)).rejects.toThrow('compute-slot: "kind" is required');
|
|
2055
|
+
});
|
|
2056
|
+
it('should throw on unknown kind', async () => {
|
|
2057
|
+
const value = {
|
|
2058
|
+
type: 'compute-slot',
|
|
2059
|
+
arguments: { kind: 'bogus' },
|
|
2060
|
+
};
|
|
2061
|
+
await expect(resolver.resolve(value, context)).rejects.toThrow('compute-slot: unknown kind "bogus"');
|
|
2062
|
+
});
|
|
2063
|
+
});
|
|
1681
2064
|
});
|
|
1682
2065
|
//# sourceMappingURL=resolver.spec.js.map
|