@@ -6,21 +6,39 @@ const expect = require('chai').expect
6
6
const base58 = require ( 'bs58' )
7
7
const fs = require ( 'fs' )
8
8
const IPFS = require ( '../../src/ipfs-core' )
9
+ const Block = require ( 'ipfs-merkle-dag' ) . Block
10
+
11
+ const isNode = ! global . window
12
+
13
+ const fileA = isNode
14
+ ? fs . readFileSync ( process . cwd ( ) + '/tests/repo-example/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data' )
15
+ : new Buffer ( require ( 'raw!./../repo-example/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data' ) )
9
16
10
17
describe ( 'block' , ( ) => {
18
+ var ipfs
19
+
11
20
it ( 'get' , done => {
12
- const ipfs = new IPFS ( )
21
+ ipfs = new IPFS ( )
13
22
const b58mh = 'QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVzxTt3qVe'
14
23
const mh = new Buffer ( base58 . decode ( b58mh ) )
15
24
ipfs . block . get ( mh , ( err , block ) => {
16
25
expect ( err ) . to . not . exist
17
- const eq = fs . readFileSync ( process . cwd ( ) + '/tests/repo-example/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data' ) . equals ( block . data )
26
+ const eq = fileA . equals ( block . data )
18
27
expect ( eq ) . to . equal ( true )
19
28
done ( )
20
29
} )
21
30
} )
22
- it . skip ( 'put' , done => {
23
- done ( )
31
+ it ( 'put' , done => {
32
+ var b = new Block ( 'random data' )
33
+ ipfs . block . put ( b , function ( err ) {
34
+ expect ( err ) . to . not . exist
35
+ ipfs . block . get ( b . key , function ( err , block ) {
36
+ expect ( err ) . to . not . exist
37
+ expect ( b . data . equals ( block . data ) ) . to . equal ( true )
38
+ expect ( b . key . equals ( block . key ) ) . to . equal ( true )
39
+ done ( )
40
+ } )
41
+ } )
24
42
} )
25
43
26
44
it ( 'rm' , done => {
@@ -42,7 +60,7 @@ describe('block', () => {
42
60
43
61
it ( 'stat' , done => {
44
62
const mh = new Buffer ( base58
45
- . decode ( 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG ' ) )
63
+ . decode ( 'QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVzxTt3qVe ' ) )
46
64
ipfs . block . stat ( mh , ( err , stats ) => {
47
65
expect ( err ) . to . not . exist
48
66
expect ( stats . Key . equals ( mh ) ) . to . equal ( true )
0 commit comments