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

Cannot create a Big Number #274

Open
aress31 opened this issue May 4, 2021 · 2 comments
Open

Cannot create a Big Number #274

aress31 opened this issue May 4, 2021 · 2 comments

Comments

@aress31
Copy link

aress31 commented May 4, 2021

I am trying to create a BN object from the value 10**32, see the following test:

  it("has a quadrilllion (10^15) initial total supply", async () => {
    const decimals = await this.token.decimals();
    const totalSupply = await this.token.totalSupply();
    // console.log(totalSupply);
    console.log(new BN(10 ** 32));
    // console.log((10 ** 15 * 10 ** decimals.toNumber()).toString());
    // console.log(totalSupply, expected);
    // expect(await this.token.totalSupply()).to.be.bignumber.equal(
    //   (10 ** 15 * 10 ** decimals.toNumber()).toString()
    // );
  });

But it seems that the library cannot handle this Big Number, see the following stack trace:

  1) Contract: Initial State
       has a quadrilllion (10^15) initial total supply:
     Error: Assertion failed
      at assert (node_modules\bn.js\lib\bn.js:6:21)
      at BN._initNumber (node_modules\bn.js\lib\bn.js:128:7)
      at BN.init [as _init] (node_modules\bn.js\lib\bn.js:82:19)
      at new BN (node_modules\bn.js\lib\bn.js:39:12)
      at Context.<anonymous> (test\ERC20Deflationary.test.js:35:17)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)

I also tried to initialise the Big Number with a string instead but the value is totally off, see:

  it("has a quadrilllion (10^15) initial total supply", async () => {
    const decimals = await this.token.decimals();
    const totalSupply = await this.token.totalSupply();
    // console.log(totalSupply);
    console.log(new BN((10 ** 32).toString()));
    // console.log((10 ** 15 * 10 ** decimals.toNumber()).toString());
    // console.log(totalSupply, expected);
    // expect(await this.token.totalSupply()).to.be.bignumber.equal(
    //   (10 ** 15 * 10 ** decimals.toNumber()).toString()
    // );
  });

  Contract: Initial State
    √ the deployer is the owner (104ms)
    √ has a name (124ms)
    √ has a symbol (124ms)
    √ has 18 decimals (87ms)
BN { negative: 0, words: [ 23532 ], length: 1, red: null }
    √ has a quadrilllion (10^15) initial total supply (173ms)
    1) assigns the initial total supply to the owner
    > No events were emitted

Could anyone please help?

@aress31
Copy link
Author

aress31 commented May 6, 2021

More details:

  it("has a quadrilllion (10^15) initial total supply", async () => {
    const decimals = await this.token.decimals();
    const totalSupply = await this.token.totalSupply();
    console.log("totalSupply", totalSupply.toString());
    console.log("1", 10 ** 32);
    console.log("2", BN(10 ** 32).toString());
    console.log("3", BN(10).exponentiatedBy(32).toString());
    // console.log(new BN(expected));
    // console.log((10 ** 15 * 10 ** decimals.toNumber()).toString());
    // console.log(totalSupply, expected);
    // expect(await this.token.totalSupply()).to.be.bignumber.equal(
    //   (10 ** 15 * 10 ** decimals.toNumber()).toString()
    // );
  });
  Contract: Initial State
    √ the deployer is the owner (95ms)
    √ has a name (96ms)
    √ has a symbol (156ms)
    √ has 18 decimals (104ms)
totalSupply 1000000000000000000000000000000000
1 1e+32
    1) has a quadrilllion (10^15) initial total supply
    > No events were emitted


  4 passing (2s)
  1 failing

  1) Contract: Initial State
       has a quadrilllion (10^15) initial total supply:
     TypeError: Cannot set property 'negative' of undefined
      at BN (node_modules\bn.js\lib\bn.js:26:19)
      at Context.<anonymous> (test\ERC20Deflationary.test.js:36:22)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)

@gentasumantri
Copy link

you should pass the exponent number as BN object, since you try to exponent a number in plain javascript. try using BN.pow() instead.

example :
const totalExp = new BN(10).pow(new BN(32))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants