@@ -5,6 +5,8 @@ import { test } from 'zinnia:test'
5
5
import { assertInstanceOf , assertEquals , assertArrayIncludes } from 'zinnia:assert'
6
6
import { SPARK_VERSION } from '../lib/constants.js'
7
7
8
+ const KNOWN_CID = 'bafkreih25dih6ug3xtj73vswccw423b56ilrwmnos4cbwhrceudopdp5sq'
9
+
8
10
test ( 'getRetrieval' , async ( ) => {
9
11
const round = {
10
12
roundId : '123' ,
@@ -47,19 +49,12 @@ test('getRetrieval', async () => {
47
49
48
50
// TODO: test more cases
49
51
test ( 'fetchCAR' , async ( ) => {
50
- const URL = 'url'
51
52
const requests = [ ]
52
- const fetch = async url => {
53
- requests . push ( { url } )
54
- return {
55
- status : 200 ,
56
- ok : true ,
57
- body : ( async function * ( ) {
58
- yield new Uint8Array ( [ 1 , 2 , 3 ] )
59
- } ) ( )
60
- }
53
+ const mockedFetch = async url => {
54
+ requests . push ( url . toString ( ) )
55
+ return fetch ( `https://frisbii.fly.dev/ipfs/${ KNOWN_CID } ` )
61
56
}
62
- const spark = new Spark ( { fetch } )
57
+ const spark = new Spark ( { fetch : mockedFetch } )
63
58
const stats = {
64
59
timeout : false ,
65
60
startAt : new Date ( ) ,
@@ -70,16 +65,16 @@ test('fetchCAR', async () => {
70
65
carChecksum : null ,
71
66
statusCode : null
72
67
}
73
- await spark . fetchCAR ( 'http' , '127.0.0.1' , 'bafy' , stats )
74
- assertEquals ( stats . timeout , false )
68
+ await spark . fetchCAR ( 'http' , '/ip4/ 127.0.0.1/tcp/80/http ' , KNOWN_CID , stats )
69
+ assertEquals ( stats . timeout , false , 'stats.timeout' )
75
70
assertInstanceOf ( stats . startAt , Date )
76
71
assertInstanceOf ( stats . firstByteAt , Date )
77
72
assertInstanceOf ( stats . endAt , Date )
78
- assertEquals ( stats . carTooLarge , false )
79
- assertEquals ( stats . byteLength , 3 )
80
- assertEquals ( stats . carChecksum , '1220039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81 ' )
81
- assertEquals ( stats . statusCode , 200 )
82
- assertEquals ( requests , [ { url : URL } ] )
73
+ assertEquals ( stats . carTooLarge , false , 'stats.carTooLarge' )
74
+ assertEquals ( stats . byteLength , 200 , 'stats.byteLength' )
75
+ assertEquals ( stats . carChecksum , '122069f03061f7ad4c14a5691b7e96d3ddd109023a6539a0b4230ea3dc92050e7136' , 'stats.carChecksum ')
76
+ assertEquals ( stats . statusCode , 200 , 'stats.statusCode' )
77
+ assertEquals ( requests , [ `http://127.0.0.1/ipfs/ ${ KNOWN_CID } ?dag-scope=block` ] )
83
78
} )
84
79
85
80
/* Disabled as long as we are fetching the top-level block only
@@ -104,7 +99,7 @@ test('fetchCAR exceeding MAX_CAR_SIZE', async () => {
104
99
carChecksum: null,
105
100
statusCode: null
106
101
}
107
- await spark.fetchCAR('http', '127.0.0.1', 'bafy', stats)
102
+ await spark.fetchCAR('http', '/ipv4/ 127.0.0.1/tcp/80/http ', 'bafy', stats)
108
103
assertEquals(stats.timeout, false)
109
104
assertEquals(stats.carTooLarge, true)
110
105
assertEquals(stats.byteLength, MAX_CAR_SIZE + 1)
0 commit comments