Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: app bigInt string values register as decimal #397

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"bridge-transaction-parser": "git+https://github.com/rsksmart/bridge-transaction-parser.git#v0.5.0-beta",
"bs58": "^5.0.0",
"dotenv": "^8.6.0",
"ethers": "^6.13.5",
"jssha": "^3.2.0",
"log4js": "^6.6.1",
"loopback-connector-kv-redis": "^4.0.0",
Expand Down
40 changes: 20 additions & 20 deletions src/__tests__/unit/register.controller.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,42 @@ describe('RegisterController', () => {
let payload = new RegisterPayload({
txHash: '0x',
type: constants.TX_TYPE_PEGIN,
value: 0.005,
value: '5000000000000000',
wallet: 'liquality',
fee: 0.000001,
fee: '1000000000000',
});
let pegoutPayload = new RegisterPayload({
txHash: '0xb',
type: constants.TX_TYPE_PEGOUT,
value: 0.004,
value: '4000000000000000',
wallet: 'liquality',
fee: 0.000002,
fee: '2000000000000',
});
let flyoverPayload = new RegisterPayload({
txHash: '0xc',
type: constants.TX_TYPE_PEGOUT,
value: 0.005,
value: '5000000000000000',
wallet: 'wallet',
fee: 0.000001,
fee: '1000000000000',
provider: 'test provider',
details: {
blocksToCompleteTransaction: 2,
blocksToCompleteTransaction: '2',
},
quote: {
callFeeOnWei: 800n,
callFeeOnWei: '800',
depositAddr: "testDeposit",
depositConfirmations: 200,
depositDateLimit: 49800,
expireBlocks: 100,
expireDate: 49850,
productFeeAmountOnWei: 6300n,
transferConfirmations: 80,
transferTime: 50600,
valueOnWei: 18450n,
agreementTimestamp: 1620000000,
gasFeeOnWei: 1000000000000000000n,
nonce: 1n,
penaltyFeeOnWei: 1000000000000000000n,
depositConfirmations: '200',
depositDateLimit: '49800',
expireBlocks: '100',
expireDate: '49850',
productFeeAmountOnWei: '6300',
transferConfirmations: '80',
transferTime: '50600',
valueOnWei: '18450',
agreementTimestamp: '1620000000',
gasFeeOnWei: '1000000000000000000',
nonce: '1000000000000000000',
penaltyFeeOnWei: '1000000000000000000',
btcRefundAddress: "testBtcRefund",
lbcAddress: "testLbc",
lpBtcAddress: "testLpBtc",
Expand Down
150 changes: 150 additions & 0 deletions src/__tests__/unit/services/flyover-service.service.unit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import { expect } from '@loopback/testlab';
import { FlyoverService } from '../../../services/flyover.service';
import { RegisterPayload } from '../../../models/register-payload.model';
import { RskNodeService } from '../../../services/rsk-node.service';
import sinon from 'sinon';
import { MongoDbDataSource } from '../../../datasources/mongodb.datasource';

describe('Service: FlyoverService', () => {
let flyoverService: FlyoverService;
let rskNodeService: RskNodeService;

beforeEach(() => {
rskNodeService = new RskNodeService();
const mongoDbDataSource = sinon.createStubInstance(MongoDbDataSource);
flyoverService = new FlyoverService(mongoDbDataSource);
});

afterEach(() => {
sinon.restore();
});
describe('Register:', () => {
it('should register a pegin native transaction successfully', async () => {
const mockBlockNumber = 1000;
sinon.stub(rskNodeService, 'getBlockNumber').resolves(mockBlockNumber);
sinon.stub(flyoverService, 'set').resolves(true);

const payload: RegisterPayload = new RegisterPayload( {
"txHash": "996de55f617c8aeb470cd8f0afd829de5169f8bedbc8bc8d45bb0ba656b0385e",
"type": "pegin",
"wallet": "leather",
"addressType": "Native segwit",
"value": "500000",
"fee": "1596"
});

const result = await flyoverService.register(payload);
expect(result).to.be.true();
});
it('should register a pegout native transaction successfully', async () => {
const mockBlockNumber = 1000;
sinon.stub(rskNodeService, 'getBlockNumber').resolves(mockBlockNumber);
sinon.stub(flyoverService, 'set').resolves(true);

const payload: RegisterPayload = new RegisterPayload( {
"txHash": "0x807f14318a2f4bc62ae3a14370c243087464740fb2f5b16763f2fb1635708bb4",
"type": "pegout",
"value": "8000000000000000",
"wallet": "Metamask",
"btcEstimatedFee": "745632",
"rskGas": "234858360000"
});

const result = await flyoverService.register(payload);
expect(result).to.be.true();
});
it('should register a pegout flyover transaction successfully', async () => {
const mockBlockNumber = 1000;
sinon.stub(rskNodeService, 'getBlockNumber').resolves(mockBlockNumber);
sinon.stub(flyoverService, 'set').resolves(true);

const payload: RegisterPayload = new RegisterPayload( {
"txHash": "0xebafb8b598395d07693e7de1e585fa518293a49b7598b5f33a525a62c09abe78",
"type": "pegout",
"value": "5000000000000000",
"wallet": "Metamask",
"rskGas": "79040000000000",
"fee": "100000000000000",
"provider": "RSK Provider",
"details": {
"senderAddress": "0x7509517a1880B14C9d734c55fAc18C7737EC11c5",
"recipientAddress": "tb1qndk5wmvg0k6p8mg2t8amr65qa4qkg8nstsnea7",
"blocksToCompleteTransaction": "10"
},
"quote": {
"agreementTimestamp": "1740092905",
"btcRefundAddress": "tb1qndk5wmvg0k6p8mg2t8amr65qa4qkg8nstsnea7",
"callFeeOnWei": "100000000000000",
"depositAddr": "tb1qndk5wmvg0k6p8mg2t8amr65qa4qkg8nstsnea7",
"depositConfirmations": "10",
"depositDateLimit": "1740100105",
"expireBlocks": "6094589",
"expireDate": "1740093405",
"gasFeeOnWei": "79040000000000",
"lbcAddress": "0xc2A630c053D12D63d32b025082f6Ba268db18300",
"liquidityProviderRskAddress": "0x7c4890a0f1d4bbf2c669ac2d1effa185c505359b",
"lpBtcAddress": "mvL2bVzGUeC9oqVyQWJ4PxQspFzKgjzAqe",
"nonce": "8353044002070248232",
"penaltyFeeOnWei": "10000000000000",
"productFeeAmountOnWei": "0",
"rskRefundAddress": "0x7509517a1880B14C9d734c55fAc18C7737EC11c5",
"transferConfirmations": "2",
"transferTime": "7200",
"valueOnWei": "5000000000000000"
},
"quoteHash": "70f5973bf6ac8d5ba00ec0f1204b4d372038a953ada2022540654d9a33511b41",
"acceptedQuoteSignature": "ba40a7fe2af7211d2fb788c5d9cbfced7caab5a932fdecc9910df450fc992b613a5118432edcf6045658f9289c0fac802d9ceba093274719d1a839897a49c67f1b"
});

const result = await flyoverService.register(payload);
expect(result).to.be.true();
});
it('should register a pegin flyover transaction successfully', async () => {
const mockBlockNumber = 1000;
sinon.stub(rskNodeService, 'getBlockNumber').resolves(mockBlockNumber);
sinon.stub(flyoverService, 'set').resolves(true);

const payload: RegisterPayload = new RegisterPayload( {
"acceptedQuoteSignature": "bab6986b5eee4e9455079155d33908b3b81ae2d090deabf8f04fcc5ef911486a4c9a7a2545af1fccfbdf56777a25c0c6a045eaba92355123454881dc0ba1f32c1c",
"addressType": "Native segwit",
"details": {
"blocksToCompleteTransaction": "2",
"recipientAddress": "0x7509517a1880b14c9d734c55fac18c7737ec11c5",
"senderAddress": "tb1qndk5wmvg0k6p8mg2t8amr65qa4qkg8nstsnea7"
},
"fee": "11028",
"provider": "teks-staging",
"quote": {
"agreementTimestamp": "1740086704",
"btcRefundAddress": "mfWxJ45yp2SFn7UciZyNpvDKrzbhyfKrY8",
"callFeeOnSatoshi": "10000",
"callOnRegister": false,
"confirmations": "2",
"contractAddr": "0x7509517a1880b14c9d734c55fac18c7737ec11c5",
"data": "0x",
"fedBTCAddr": "2N3GznpmcBbymsK53Q1eh4NCorKbYN9wKr2",
"gasFeeOnWei": "111872628000",
"gasLimit": "21000",
"lbcAddress": "0xc2A630c053D12D63d32b025082f6Ba268db18300",
"liquidityProviderRskAddress": "0x113ed582b39490cada59b7fc6cffe1dd4cba5e4b",
"lpBtcAddress": "mtkgpHyZzRspgkt3nUNV7xJRrwnMCPbuPW",
"lpCallTime": "14400",
"nonce": "1746424005804806700",
"penaltyFeeOnWei": "10000000000000",
"productFeeAmountOnSatoshi": "0",
"rskRefundAddress": "0x7509517a1880b14c9d734c55fac18c7737ec11c5",
"timeForDepositInSeconds": "10800",
"valueOnSatoshi": "500000"
},
"quoteHash": "f49c2190c649100e26518937bf072eb172c5e938089f277ebbb2e355dcf00ddc",
"txHash": "da7cc5b956607830e70c13ab26225439f2f2a427715ed81d8ca714bdf381d7ce",
"type": "pegin",
"value": "500000",
"wallet": "leather"
});

const result = await flyoverService.register(payload);
expect(result).to.be.true();
});
});
});
17 changes: 17 additions & 0 deletions src/__tests__/unit/utils/parse-units.unit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {stringWeiToDecimalString, stringSatoshiToDecimalString} from '../../../utils/parseUnits';
import {expect} from '@loopback/testlab';

describe('ParseUnits', () => {
it('should get the decimal string value of a satoshi string', () => {
const stringValueInSatoshis = "1596";
expect(stringSatoshiToDecimalString(stringValueInSatoshis)).to.be.eql("0.00001596");
});
it('should get the decimal string value of a wei string', () => {
const stringValueInWei = "79040000000000";
expect(stringWeiToDecimalString(stringValueInWei)).to.be.eql("0.00007904");
});
it('should return zero string value of a satoshi string 0', () => {
const stringValueInSatoshis = "0";
expect(stringSatoshiToDecimalString(stringValueInSatoshis)).to.be.eql("0");
});
});
8 changes: 4 additions & 4 deletions src/models/app-tx.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ export class AppTxModel implements SearchableModel {
txHash: string;
type: string;
creationDate: Date;
value: number;
value: string;
wallet: string;
addressType: string;
fee: number;
rskGas: number;
btcEstimatedFee: number;
fee: string;
rskGas: string;
btcEstimatedFee: string;
provider: string;

getId() {
Expand Down
4 changes: 2 additions & 2 deletions src/models/flyover-status.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export class FlyoverStatusModel implements SearchableModel {
txHash: string;
type: string;
date: Date;
amount: number;
fee: number;
amount: string;
fee: string;
blockToBeFinished: number;
senderAddress: string;
recipientAddress: string;
Expand Down
Loading
Loading