Skip to content

Commit

Permalink
fixing bug with display string (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffywu authored Sep 28, 2022
1 parent 1e084a2 commit 2a2f481
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/libs/TypedBigNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class TypedBigNumber {
});

// If the return string is -0.00 or some variant, strip the negative
if (displayString.match(/-0\.?[0]*/)) {
if (displayString.match(/-0\.?[0]*$/)) {
return displayString.replace('-', '');
}

Expand Down
38 changes: 19 additions & 19 deletions tests/integration/transactions.test.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
import {expect} from 'chai';
import Notional, { TypedBigNumber } from '../../src';
import { expect } from 'chai';
import { ethers } from 'hardhat';
import { getAccount, setChainState } from './utils';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { BigNumber } from 'ethers';
import { getAccount, setChainState } from './utils';
import Notional, { TypedBigNumber } from '../../src';

const forkedBlockNumber = 15104800;
const DAI_WHALE = "0x8B64fA5Fd129df9c755eB82dB1e16D6D0Bdf5Bc3"
const DAI_WHALE = '0x8B64fA5Fd129df9c755eB82dB1e16D6D0Bdf5Bc3';

describe('transactions', () => {
let notional: Notional;
let daiWhale: SignerWithAddress;
let daiWhale: SignerWithAddress;

beforeEach(async () => {
await setChainState(forkedBlockNumber);
daiWhale = await getAccount(DAI_WHALE);

if (notional === undefined) {
const provider = new ethers.providers.JsonRpcBatchProvider("http://localhost:8545")
notional = await Notional.load(1, provider)
const provider = new ethers.providers.JsonRpcBatchProvider('http://localhost:8545');
notional = await Notional.load(1, provider);
}
})
});

it('executes a batch lend transaction', async () => {
const contract = notional.system.getCurrencyBySymbol("DAI").underlyingContract
await contract?.connect(daiWhale).approve(notional.system.getNotionalProxy().address, ethers.constants.MaxUint256)
const contract = notional.system.getCurrencyBySymbol('DAI').underlyingContract;
await contract?.connect(daiWhale).approve(notional.system.getNotionalProxy().address, ethers.constants.MaxUint256);
const populatedTxn = await notional.batchLend(
DAI_WHALE,
"DAI",
TypedBigNumber.fromBalance(10e8, "DAI", true),
'DAI',
TypedBigNumber.fromBalance(10e8, 'DAI', true),
1,
0
)
);
// Gas estimation inside hardhat is wrong
populatedTxn.gasLimit = BigNumber.from(2_500_000)
await daiWhale.sendTransaction(populatedTxn)
const { portfolio } = await notional.system.getNotionalProxy().connect(daiWhale).getAccount(DAI_WHALE)
expect(portfolio.length).to.equal(1)
expect(portfolio[0].currencyId.toNumber()).to.equal(2)
expect(portfolio[0].notional.toNumber()).to.equal(10e8)
populatedTxn.gasLimit = BigNumber.from(2_500_000);
await daiWhale.sendTransaction(populatedTxn);
const { portfolio } = await notional.system.getNotionalProxy().connect(daiWhale).getAccount(DAI_WHALE);
expect(portfolio.length).to.equal(1);
expect(portfolio[0].currencyId.toNumber()).to.equal(2);
expect(portfolio[0].notional.toNumber()).to.equal(10e8);
});
});
50 changes: 36 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,10 @@
"@ethersproject/properties" "^5.0.3"
"@ethersproject/strings" "^5.0.4"

"@ethersproject/abi@5.6.3", "@ethersproject/abi@^5.6.3":
version "5.6.3"
resolved "https://registry.yarnpkg.com/@ethersproject/abi/-/abi-5.6.3.tgz#2d643544abadf6e6b63150508af43475985c23db"
integrity sha512-CxKTdoZY4zDJLWXG6HzNH6znWK0M79WzzxHegDoecE3+K32pzfHOzuXg2/oGSTecZynFgpkjYXNPOqXVJlqClw==
"@ethersproject/abi@5.6.4":
version "5.6.4"
resolved "https://registry.yarnpkg.com/@ethersproject/abi/-/abi-5.6.4.tgz#f6e01b6ed391a505932698ecc0d9e7a99ee60362"
integrity sha512-TTeZUlCeIHG6527/2goZA6gW5F8Emoc7MrZDC7hhP84aRGvW3TEdTnZR08Ls88YXM1m2SuK42Osw/jSi3uO8gg==
dependencies:
"@ethersproject/address" "^5.6.1"
"@ethersproject/bignumber" "^5.6.2"
Expand All @@ -590,6 +590,21 @@
"@ethersproject/properties" "^5.5.0"
"@ethersproject/strings" "^5.5.0"

"@ethersproject/abi@^5.6.3":
version "5.6.3"
resolved "https://registry.yarnpkg.com/@ethersproject/abi/-/abi-5.6.3.tgz#2d643544abadf6e6b63150508af43475985c23db"
integrity sha512-CxKTdoZY4zDJLWXG6HzNH6znWK0M79WzzxHegDoecE3+K32pzfHOzuXg2/oGSTecZynFgpkjYXNPOqXVJlqClw==
dependencies:
"@ethersproject/address" "^5.6.1"
"@ethersproject/bignumber" "^5.6.2"
"@ethersproject/bytes" "^5.6.1"
"@ethersproject/constants" "^5.6.1"
"@ethersproject/hash" "^5.6.1"
"@ethersproject/keccak256" "^5.6.1"
"@ethersproject/logger" "^5.6.0"
"@ethersproject/properties" "^5.6.0"
"@ethersproject/strings" "^5.6.1"

"@ethersproject/abstract-provider@5.6.1", "@ethersproject/abstract-provider@^5.6.1":
version "5.6.1"
resolved "https://registry.yarnpkg.com/@ethersproject/abstract-provider/-/abstract-provider-5.6.1.tgz#02ddce150785caf0c77fe036a0ebfcee61878c59"
Expand Down Expand Up @@ -927,10 +942,10 @@
resolved "https://registry.yarnpkg.com/@ethersproject/logger/-/logger-5.5.0.tgz#0c2caebeff98e10aefa5aef27d7441c7fd18cf5d"
integrity sha512-rIY/6WPm7T8n3qS2vuHTUBPdXHl+rGxWxW5okDfo9J4Z0+gRRZT0msvUdIJkE4/HS29GUMziwGaaKO2bWONBrg==

"@ethersproject/networks@5.6.3", "@ethersproject/networks@^5.6.3":
version "5.6.3"
resolved "https://registry.yarnpkg.com/@ethersproject/networks/-/networks-5.6.3.tgz#3ee3ab08f315b433b50c99702eb32e0cf31f899f"
integrity sha512-QZxRH7cA5Ut9TbXwZFiCyuPchdWi87ZtVNHWZd0R6YFgYtes2jQ3+bsslJ0WdyDe0i6QumqtoYqvY3rrQFRZOQ==
"@ethersproject/networks@5.6.4":
version "5.6.4"
resolved "https://registry.yarnpkg.com/@ethersproject/networks/-/networks-5.6.4.tgz#51296d8fec59e9627554f5a8a9c7791248c8dc07"
integrity sha512-KShHeHPahHI2UlWdtDMn2lJETcbtaJge4k7XSjDR9h79QTd6yQJmv6Cp2ZA4JdqWnhszAOLSuJEd9C0PRw7hSQ==
dependencies:
"@ethersproject/logger" "^5.6.0"

Expand All @@ -948,6 +963,13 @@
dependencies:
"@ethersproject/logger" "^5.5.0"

"@ethersproject/networks@^5.6.3":
version "5.6.3"
resolved "https://registry.yarnpkg.com/@ethersproject/networks/-/networks-5.6.3.tgz#3ee3ab08f315b433b50c99702eb32e0cf31f899f"
integrity sha512-QZxRH7cA5Ut9TbXwZFiCyuPchdWi87ZtVNHWZd0R6YFgYtes2jQ3+bsslJ0WdyDe0i6QumqtoYqvY3rrQFRZOQ==
dependencies:
"@ethersproject/logger" "^5.6.0"

"@ethersproject/pbkdf2@5.6.1", "@ethersproject/pbkdf2@^5.6.1":
version "5.6.1"
resolved "https://registry.yarnpkg.com/@ethersproject/pbkdf2/-/pbkdf2-5.6.1.tgz#f462fe320b22c0d6b1d72a9920a3963b09eb82d1"
Expand Down Expand Up @@ -3345,12 +3367,12 @@ ethereumjs-util@^7.1.5:
ethereum-cryptography "^0.1.3"
rlp "^2.2.4"

ethers@5.6.8:
version "5.6.8"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.6.8.tgz#d36b816b4896341a80a8bbd2a44e8cb6e9b98dd4"
integrity sha512-YxIGaltAOdvBFPZwIkyHnXbW40f1r8mHUgapW6dxkO+6t7H6wY8POUn0Kbxrd/N7I4hHxyi7YCddMAH/wmho2w==
ethers@5.6.9:
version "5.6.9"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.6.9.tgz#4e12f8dfcb67b88ae7a78a9519b384c23c576a4d"
integrity sha512-lMGC2zv9HC5EC+8r429WaWu3uWJUCgUCt8xxKCFqkrFuBDZXDYIdzDUECxzjf2BMF8IVBByY1EBoGSL3RTm8RA==
dependencies:
"@ethersproject/abi" "5.6.3"
"@ethersproject/abi" "5.6.4"
"@ethersproject/abstract-provider" "5.6.1"
"@ethersproject/abstract-signer" "5.6.2"
"@ethersproject/address" "5.6.1"
Expand All @@ -3365,7 +3387,7 @@ ethers@5.6.8:
"@ethersproject/json-wallets" "5.6.1"
"@ethersproject/keccak256" "5.6.1"
"@ethersproject/logger" "5.6.0"
"@ethersproject/networks" "5.6.3"
"@ethersproject/networks" "5.6.4"
"@ethersproject/pbkdf2" "5.6.1"
"@ethersproject/properties" "5.6.0"
"@ethersproject/providers" "5.6.8"
Expand Down

0 comments on commit 2a2f481

Please sign in to comment.