-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
56 lines (44 loc) · 1.24 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var path = require('path');
var main = require(path.join(__dirname, 'index.js'));
var assert = require('chai').assert;
function isJson(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
describe('main', function () {
var persist = '';
it('should save json in ipfs', function (done) {
main.save(JSON.stringify({
"hello": "world",
"from": "ipfs-play (https://github.com/insanity54/ipfs-play)"
}), function (err, hash) {
assert.isNull(err);
assert.match(hash, /[a-zA-Z0-9]{46}/);
persist = hash;
done();
});
});
it('should load json from ipfs', function (done) {
main.load(persist, function (err, data) {
assert.isNull(err);
assert.isNotNull(data);
assert.isTrue(isJson(data), 'game data retrieved from ipfs is not json');
console.log(data);
done();
});
});
it('should successfully cat old hashes', function (done) {
main.load('QmZd9ayjiEBgJDKHJsLeavCLzCsqnKxQKU2ZGuJwz1SWGq', function (err, data) {
assert.isNull(err);
assert.isNotNull(data);
assert.isTrue(isJson(data), 'game data retrieved from ipfs is not json');
console.log(data);
console.log('^ data');
done();
});
});
});