-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbase58-tests.js
44 lines (36 loc) · 1.28 KB
/
base58-tests.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
Tinytest.add('Encoding result should be a string', function(test) {
var clear = 'Some words here.';
var encoded = Base58.encode(clear);
test.equal(typeof encoded, 'string');
});
Tinytest.add('Base58 algorithm is symetrical', function(test) {
var clear = 'This is a clear string';
test.equal(Base58.decode(Base58.encode(clear)), clear);
});
// Buffer is only defined in NodeJS context
if (Meteor.isServer) {
Tinytest.add('Encoding Buffer instance', function(test) {
var clear = 'This is a clear string';
var buffer = new Buffer(clear);
var encodedBuffer = Base58.encode(buffer);
test.equal(encodedBuffer, Base58.encode(clear));
});
}
Tinytest.add('Encoding byte array', function(test) {
var clear = 'This is a clear string';
var bytes = [];
for (var i = 0; i < clear.length; i++) {
bytes.push(clear.charCodeAt(i));
}
var encodedBytes = Base58.encode(bytes);
test.equal(encodedBytes, Base58.encode(clear));
});
Tinytest.add('Decoding as byte array', function(test) {
var clear = 'This is a clear string';
var encoded = Base58.encode(clear);
var bytes = [];
for (var i = 0; i < clear.length; i++) {
bytes.push(clear.charCodeAt(i));
}
test.equal(Base58.decodeArray(encoded), bytes);
});