Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
fix: allowing addresses to be Uint8Array (#665)
Browse files Browse the repository at this point in the history
fix: upgraded bootstrap to latest alpha (with https support)
  • Loading branch information
fboucquez authored Oct 15, 2021
1 parent 9c1eef0 commit fc12568
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 60 deletions.
8 changes: 4 additions & 4 deletions rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"lint:jenkins": "eslint -o tests.catapult.lint.xml -f junit src test || exit 0",
"bootstrap-clean": "symbol-bootstrap clean",
"bootstrap-start": "symbol-bootstrap start -a light -c bootstrap-preset-local.yml --healthCheck --noPassword",
"bootstrap-start-testnet": "symbol-bootstrap start -p testnet -a dual -c bootstrap-preset-testnet.yml --healthCheck --noPassword",
"bootstrap-start-mainnet": "symbol-bootstrap start -p testnet -a dual -c bootstrap-preset-mainnet.yml --healthCheck --noPassword",
"bootstrap-start-detached": "symbol-bootstrap start -a light -c bootstrap-preset.yml --detached --healthCheck --noPassword",
"bootstrap-start-testnet": "symbol-bootstrap start -p testnet -a dual -c bootstrap-preset-testnet.yml --healthCheck --noPassword --upgrade",
"bootstrap-start-mainnet": "symbol-bootstrap start -p testnet -a dual -c bootstrap-preset-mainnet.yml --healthCheck --noPassword --upgrade",
"bootstrap-start-detached": "symbol-bootstrap start -a light -c bootstrap-preset.yml --detached --healthCheck --noPassword --upgrade",
"bootstrap-stop": "symbol-bootstrap stop",
"bootstrap-run": "symbol-bootstrap run",
"bootstrap-run-detached": "symbol-bootstrap run --detached --healthCheck",
Expand Down Expand Up @@ -46,7 +46,7 @@
"nyc": "^14.1.1",
"rimraf": "^2.6.3",
"sinon": "^7.3.2",
"symbol-bootstrap": "^1.0.8-alpha-202108171450"
"symbol-bootstrap": "^1.1.0-alpha-202110051739"
},
"dependencies": {
"catapult-sdk": "link:../catapult-sdk",
Expand Down
12 changes: 9 additions & 3 deletions rest/src/db/dbUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,16 @@ const dbUtils = {
* @returns {string} AddressBase32|NamespaceId
*/
bufferToUnresolvedAddress: binary => {
if (!(binary instanceof MongoDb.Binary))
if (!binary)
return undefined;
// return as Address base 32
return address.addressToString(binary.buffer);

if ((binary instanceof MongoDb.Binary))
return address.addressToString(binary.buffer);

if ((binary instanceof Uint8Array))
return address.addressToString(binary);

throw new Error(`Cannot convert binary address, unknown ${binary.constructor.name} type`);
},

/**
Expand Down
25 changes: 22 additions & 3 deletions rest/test/db/dbUtils_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe('db utils', () => {
});

describe('bufferToUnresolvedAddress', () => {
it('can convert from buffer to Address', () => {
it('can convert from Binary to Address', () => {
// Arrange
const object = new Binary(Buffer.from('98E0D138EAF2AC342C015FF0B631EC3622E8AFFA04BFCC56', 'hex'));

Expand All @@ -180,15 +180,34 @@ describe('db utils', () => {
expect(result).to.equal('TDQNCOHK6KWDILABL7YLMMPMGYRORL72AS74YVQ');
});

it('cannot convert from invalid data type', () => {
it('can convert from Buffer to Address', () => {
// Arrange
const object = '99CAAB0FD01CCF25BA000000000000000000000000000000';
const object = Buffer.from('98E0D138EAF2AC342C015FF0B631EC3622E8AFFA04BFCC56', 'hex');

// Act:
const result = dbUtils.bufferToUnresolvedAddress(object);

// Assert:
expect(result).to.equal('TDQNCOHK6KWDILABL7YLMMPMGYRORL72AS74YVQ');
});

it('can convert from undefined to undefined address', () => {
// Arrange
const object = undefined;

// Act:
const result = dbUtils.bufferToUnresolvedAddress(object);

// Assert:
expect(result).to.equal(undefined);
});

it('cannot convert from invalid data type', () => {
// Arrange
const object = '99CAAB0FD01CCF25BA000000000000000000000000000000';

// act + Assert:
expect(() => dbUtils.bufferToUnresolvedAddress(object)).to.throw('Cannot convert binary address, unknown String type');
});
});
});
Loading

0 comments on commit fc12568

Please sign in to comment.