Skip to content

Commit

Permalink
[dependency] fix: upgrade the symbol-sdk for faucet
Browse files Browse the repository at this point in the history
problem: symbol-sdk 3.2.1 does not have a default import
solution: use named imports instead of default
  • Loading branch information
Wayonb committed Apr 24, 2024
1 parent b131142 commit f92f614
Show file tree
Hide file tree
Showing 9 changed files with 3,095 additions and 14,964 deletions.
7,627 changes: 1,507 additions & 6,120 deletions faucet/backend/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion faucet/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"restify": "^11.1.0",
"restify-errors": "^8.0.2",
"sqlite3": "^5.1.6",
"symbol-sdk": "^3.0.11",
"symbol-sdk": "^3.2.1",
"winston": "^3.10.0"
},
"devDependencies": {
Expand Down
11 changes: 5 additions & 6 deletions faucet/backend/src/facade/nemFacade.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { config } from '../config/index.js';
import createNemClient from '../services/nemClient.js';
import helper from '../utils/helper.js';
import symbolSDK from 'symbol-sdk';

const { PrivateKey, facade, nem } = symbolSDK;
import { PrivateKey } from 'symbol-sdk';
import { NemFacade, NetworkTimestamp } from 'symbol-sdk/nem';

const nemFacade = {
facade: new facade.NemFacade(config.network),
faucetKeyPair: new facade.NemFacade.KeyPair(new PrivateKey(config.nem.faucetPrivateKey)),
facade: new NemFacade(config.network),
faucetKeyPair: new NemFacade.KeyPair(new PrivateKey(config.nem.faucetPrivateKey)),
client: createNemClient(config.nem),

/**
Expand Down Expand Up @@ -51,7 +50,7 @@ const nemFacade = {
async transfer(amount, recipientAddress) {
const timestamp = await nemFacade.getNetworkTimestamp();

const networkTimestamp = new nem.NetworkTimestamp(timestamp);
const networkTimestamp = new NetworkTimestamp(timestamp);

const transferTransaction = this.facade.transactionFactory.create({
type: 'transfer_transaction_v1',
Expand Down
11 changes: 5 additions & 6 deletions faucet/backend/src/facade/symbolFacade.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { config } from '../config/index.js';
import createSymbolClient from '../services/symbolClient.js';
import helper from '../utils/helper.js';
import symbolSdk from 'symbol-sdk';

const { PrivateKey, facade, symbol } = symbolSdk;
import { PrivateKey } from 'symbol-sdk';
import { NetworkTimestamp, SymbolFacade } from 'symbol-sdk/symbol';

const symbolFacade = {
facade: new facade.SymbolFacade(config.network),
faucetKeyPair: new facade.SymbolFacade.KeyPair(new PrivateKey(config.symbol.faucetPrivateKey)),
facade: new SymbolFacade(config.network),
faucetKeyPair: new SymbolFacade.KeyPair(new PrivateKey(config.symbol.faucetPrivateKey)),
client: createSymbolClient(config.symbol),

/**
Expand Down Expand Up @@ -69,7 +68,7 @@ const symbolFacade = {
recipientAddress,
mosaics,
message: [0, ...(new TextEncoder('utf-8')).encode('Good Luck!')],
deadline: new symbol.NetworkTimestamp(networkTimestamp).addHours(2).timestamp
deadline: new NetworkTimestamp(networkTimestamp).addHours(2).timestamp
});

const { payload, transactionHash } = helper.signTransaction(this.facade, this.faucetKeyPair, transferTransaction);
Expand Down
6 changes: 2 additions & 4 deletions faucet/backend/src/services/symbolClient.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { axiosErrorHandler, client } from '../utils/axiosRequest.js';
import symbolSdk from 'symbol-sdk';

const { PrivateKey, facade } = symbolSdk;
const { SymbolFacade } = facade;
import { PrivateKey } from 'symbol-sdk';
import { SymbolFacade } from 'symbol-sdk/symbol';

const createSymbolClient = ({ endpoint, faucetPrivateKey }) => ({
axios: client(endpoint),
Expand Down
16 changes: 8 additions & 8 deletions faucet/backend/test/utils/helper_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { config } from '../../src/config/index.js';
import helper from '../../src/utils/helper.js';
import { expect } from 'chai';
import symbolSDK from 'symbol-sdk';
import { PrivateKey } from 'symbol-sdk';
import { NemFacade } from 'symbol-sdk/nem';
import { NetworkTimestamp, SymbolFacade } from 'symbol-sdk/symbol';

describe('helper', () => {
it('can convert absolute amount to relative amount.', () => {
Expand Down Expand Up @@ -124,12 +126,10 @@ describe('helper', () => {
});

describe('signTransaction', () => {
const { PrivateKey, facade, symbol } = symbolSDK;

it('returns signed transaction hash and payload when nem facade provided', () => {
// Arrange:
const protocolFacade = new facade.NemFacade(config.network);
const keyPair = new facade.NemFacade.KeyPair(new PrivateKey(config.nem.faucetPrivateKey));
const protocolFacade = new NemFacade(config.network);
const keyPair = new NemFacade.KeyPair(new PrivateKey(config.nem.faucetPrivateKey));
const networkTimestamp = 10000;

const transferTransaction = protocolFacade.transactionFactory.create({
Expand Down Expand Up @@ -160,8 +160,8 @@ describe('helper', () => {

it('returns signed transaction hash and payload when symbol facade provided', () => {
// Arrange:
const protocolFacade = new facade.SymbolFacade(config.network);
const keyPair = new facade.SymbolFacade.KeyPair(new PrivateKey(config.symbol.faucetPrivateKey));
const protocolFacade = new SymbolFacade(config.network);
const keyPair = new SymbolFacade.KeyPair(new PrivateKey(config.symbol.faucetPrivateKey));

const transferTransaction = protocolFacade.transactionFactory.create({
type: 'transfer_transaction_v1',
Expand All @@ -170,7 +170,7 @@ describe('helper', () => {
recipientAddress: 'TBL6O45I3HL2J3X3LPRVCEAES3S6KTWLNZ76NDQ',
mosaics: [],
message: [],
deadline: new symbol.NetworkTimestamp(10000).addHours(2).timestamp
deadline: new NetworkTimestamp(10000).addHours(2).timestamp
});

// Act:
Expand Down
Loading

0 comments on commit f92f614

Please sign in to comment.