@@ -1798,27 +1798,25 @@ describe('MirrorNodeClient', async function () {
1798
1798
mock . onGet ( contractStatePath ) . reply ( 200 , JSON . stringify ( mockContractState ) ) ;
1799
1799
const result = await mirrorNodeInstance . getContractState ( contractAddress , requestDetails ) ;
1800
1800
expect ( result ) . to . exist ;
1801
- expect ( result . state ) . to . exist ;
1802
- expect ( result . state . length ) . to . equal ( 2 ) ;
1803
- expect ( result . state [ 0 ] . address ) . to . equal ( contractAddress ) ;
1804
- expect ( result . state [ 0 ] . slot ) . to . equal ( mockContractState . state [ 0 ] . slot ) ;
1805
- expect ( result . state [ 0 ] . value ) . to . equal ( mockContractState . state [ 0 ] . value ) ;
1801
+ expect ( result . length ) . to . equal ( 2 ) ;
1802
+ expect ( result [ 0 ] . address ) . to . equal ( contractAddress ) ;
1803
+ expect ( result [ 0 ] . slot ) . to . equal ( mockContractState . state [ 0 ] . slot ) ;
1804
+ expect ( result [ 0 ] . value ) . to . equal ( mockContractState . state [ 0 ] . value ) ;
1806
1805
} ) ;
1807
1806
1808
1807
it ( 'should fetch contract state with blockEndTimestamp' , async ( ) => {
1809
1808
mock . onGet ( contractStatePathWithTimestamp ) . reply ( 200 , JSON . stringify ( mockContractState ) ) ;
1810
1809
const result = await mirrorNodeInstance . getContractState ( contractAddress , requestDetails , blockEndTimestamp ) ;
1811
1810
expect ( result ) . to . exist ;
1812
- expect ( result . state ) . to . exist ;
1813
- expect ( result . state . length ) . to . equal ( 2 ) ;
1814
- expect ( result . state [ 0 ] . address ) . to . equal ( contractAddress ) ;
1815
- expect ( result . state [ 0 ] . timestamp ) . to . equal ( blockEndTimestamp ) ;
1811
+ expect ( result . length ) . to . equal ( 2 ) ;
1812
+ expect ( result [ 0 ] . address ) . to . equal ( contractAddress ) ;
1813
+ expect ( result [ 0 ] . timestamp ) . to . equal ( blockEndTimestamp ) ;
1816
1814
} ) ;
1817
1815
1818
- it ( 'should return null when contract state is not found' , async ( ) => {
1816
+ it ( 'should return empty array when contract state is not found' , async ( ) => {
1819
1817
mock . onGet ( contractStatePath ) . reply ( 404 , JSON . stringify ( mockData . notFound ) ) ;
1820
1818
const result = await mirrorNodeInstance . getContractState ( contractAddress , requestDetails ) ;
1821
- expect ( result ) . to . be . null ;
1819
+ expect ( result ) . to . be . empty ;
1822
1820
} ) ;
1823
1821
1824
1822
it ( 'should throw error for invalid contract address' , async ( ) => {
@@ -1845,5 +1843,66 @@ describe('MirrorNodeClient', async function () {
1845
1843
}
1846
1844
expect ( errorRaised ) . to . be . true ;
1847
1845
} ) ;
1846
+
1847
+ it ( 'should handle pagination and consolidate results from multiple pages' , async ( ) => {
1848
+ // Mock first page with a next link
1849
+ const firstPageResponse = {
1850
+ state : [
1851
+ {
1852
+ address : contractAddress ,
1853
+ contract_id : '0.0.5001' ,
1854
+ timestamp : '1653077541.983983199' ,
1855
+ slot : '0x0000000000000000000000000000000000000000000000000000000000000101' ,
1856
+ value : '0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925' ,
1857
+ } ,
1858
+ {
1859
+ address : contractAddress ,
1860
+ contract_id : '0.0.5001' ,
1861
+ timestamp : '1653077541.983983199' ,
1862
+ slot : '0x0000000000000000000000000000000000000000000000000000000000000102' ,
1863
+ value : '0x9c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b926' ,
1864
+ } ,
1865
+ ] ,
1866
+ links : {
1867
+ next : '/api/v1/contracts/results/0x7e08d3df45823dc56298a9a097f8cb9bde2f99c4e114b569a9aff3eb227e4d23/actions?limit=2&order=desc&index=lt:8' ,
1868
+ } ,
1869
+ } ;
1870
+
1871
+ // Mock second page with no next link (final page)
1872
+ const secondPageResponse = {
1873
+ state : [
1874
+ {
1875
+ address : contractAddress ,
1876
+ contract_id : '0.0.5001' ,
1877
+ timestamp : '1653077541.983983199' ,
1878
+ slot : '0x0000000000000000000000000000000000000000000000000000000000000103' ,
1879
+ value : '0xac5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b927' ,
1880
+ } ,
1881
+ ] ,
1882
+ links : {
1883
+ next : null ,
1884
+ } ,
1885
+ } ;
1886
+
1887
+ // Setup mocks for both pages
1888
+ mock . onGet ( contractStatePath ) . reply ( 200 , JSON . stringify ( firstPageResponse ) ) ;
1889
+ mock
1890
+ . onGet (
1891
+ 'contracts/results/0x7e08d3df45823dc56298a9a097f8cb9bde2f99c4e114b569a9aff3eb227e4d23/actions?limit=2&order=desc&index=lt:8' ,
1892
+ )
1893
+ . reply ( 200 , JSON . stringify ( secondPageResponse ) ) ;
1894
+
1895
+ // Call the method
1896
+ const result = await mirrorNodeInstance . getContractState ( contractAddress , requestDetails ) ;
1897
+
1898
+ // Verify the results are merged correctly
1899
+ expect ( result ) . to . exist ;
1900
+ expect ( result . length ) . to . equal ( 3 ) ;
1901
+ expect ( result [ 0 ] . address ) . to . equal ( contractAddress ) ;
1902
+ expect ( result [ 0 ] . slot ) . to . equal ( firstPageResponse . state [ 0 ] . slot ) ;
1903
+ expect ( result [ 0 ] . value ) . to . equal ( firstPageResponse . state [ 0 ] . value ) ;
1904
+ expect ( result [ 2 ] . slot ) . to . equal ( secondPageResponse . state [ 0 ] . slot ) ;
1905
+ expect ( result [ 2 ] . value ) . to . equal ( secondPageResponse . state [ 0 ] . value ) ;
1906
+ } ) ;
1848
1907
} ) ;
1849
1908
} ) ;
0 commit comments