Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("decodeString", function () {
var result = openchain.encoding.decodeString(ByteBuffer.fromHex("414243"));
assert.equal(result, "ABC");
});
it("decodeInt64", function () {
var result1 = openchain.encoding.decodeInt64(ByteBuffer.fromHex("00000000000061a8"));
var result2 = openchain.encoding.decodeInt64(ByteBuffer.fromHex(""));
assert.deepEqual(result1, Long.fromString("25000", false));
assert.deepEqual(result2, Long.fromString("0", false));
});
});
it("parse ByteBuffer", function () {
var result = RecordKey.parse(ByteBuffer.fromHex("2f6163636f756e742f706174682f3a4143433a2f61737365742f706174682f"));
assert.equal(result.path.toString(), "/account/path/");
assert.equal(result.recordType, "ACC");
assert.equal(result.name, "/asset/path/");
});
it('getDataRecord with version', function () {
return client.getDataRecord("/", "info", ByteBuffer.fromHex("")).then(function (result) {
assert.equal(result.key.toHex(), "2f3a444154413a696e666f");
assert.equal(result.value.toHex(), "");
assert.equal(result.version.toHex(), "");
assert.equal(result.data, null);
});
});
it("addRecord", function () {
var builder = new TransactionBuilder(new ApiClientMock());
builder.addRecord(ByteBuffer.fromHex("ab"), ByteBuffer.fromHex("cd"), ByteBuffer.fromHex("ef"));
builder.addRecord(ByteBuffer.fromHex("12"), null, ByteBuffer.fromHex("34"));
assert.deepEqual(builder.records, [
{ "key": ByteBuffer.fromHex("ab"), "value": { "data": ByteBuffer.fromHex("cd") }, "version": ByteBuffer.fromHex("ef") },
{ "key": ByteBuffer.fromHex("12"), "value": null, "version": ByteBuffer.fromHex("34") }
]);
});
it('getRecord fail', function () {
return client.getRecord("/:DATA:info", ByteBuffer.fromHex("abcd")).then(function (result) {
assert.fail();
}, function (err) {
assert.equal(404, err.statusCode);
});
});
it('getRecord ByteBuffer', function () {
return client.getRecord(ByteBuffer.fromHex("0000")).then(function (result) {
assert.equal(result.key.toHex(), "0000");
assert.equal(result.value.toHex(), "");
assert.equal(result.version.toHex(), "");
});
});
it("build", function () {
var builder = new TransactionBuilder(new ApiClientMock());
builder.addRecord(ByteBuffer.fromHex("ab"), ByteBuffer.fromHex("cd"), ByteBuffer.fromHex("ef"));
builder.addRecord(ByteBuffer.fromHex("12"), null, ByteBuffer.fromHex("34"));
builder.setMetadata({ "hello": "world" });
var result = builder.build();
assert.equal(result.toHex(), "0a03abcdef120b0a01ab12030a01cd1a01ef12060a01121a01341a117b2268656c6c6f223a22776f726c64227d");
});
this.getDataRecord = function (path, recordName) {
var key = new RecordKey(path, "DATA", recordName).toByteBuffer();
var result;
if (recordName == "goto" && _this.gotoRecords[path]) {
result = _this.gotoRecords[path];
}
else {
result = null;
}
return q.resolve({ data: result, key: key, version: ByteBuffer.fromHex("aaaa") });
};
return this.getInfo().then(function (result) {
_this.namespace = ByteBuffer.fromHex(result.namespace);
});
};