Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
257 views
in Technique[技术] by (71.8m points)

javascript - Console.log [BN] did not show the value

I am looking at the log result of the variable "result". By running a few test, i am pretty sure inside the id and the price has value. However the console logs only show [BN] instead of <BN:1>. How can it print out the value in console logs?

Smart Contract fucntion:

function createProduct(string memory _name, uint _price) public {
    productCount ++;
    products[productCount] = Product(productCount, _name, _price, msg.sender, false);
    emit ProductCreated(productCount, _name, _price, msg.sender, false);
}

Test code:

describe('products', async() => {
    let productCount, result

    before (async () => {
        result = await marketplace.createProduct('iphone x', web3.utils.toWei('1','Ether'));
        productCount = await marketplace.productCount();
    } )

    it('creates products', async () => {
        // SUCESS
        assert.equal(productCount, 1);
        console.log(result.logs);
    })        
})

Result:

args: Result {
  '0': [BN],
  '1': 'iphone x',
  '2': [BN],
  '3': '0xa1e26adB8eF905FdE80bBf9ed88D6784618a5B1b',
  '4': false,
  __length__: 5,
  id: [BN],
  name: 'iphone x',
  price: [BN],
  owner: '0xa1e26adB8eF905FdE80bBf9ed88D6784618a5B1b',
  purchased: false

Expected result:

args: Result {
  '0': <BN:1>,
  '1': 'iphone x',
  '2': <BN:de0b6b3a7640000>,
  '3': '0xa1e26adB8eF905FdE80bBf9ed88D6784618a5B1b',
  '4': false,
  __length__: 5,
  id: <BN:1>,
  name: 'iphone x',
  price: <BN:de0b6b3a7640000>,
  owner: '0xa1e26adB8eF905FdE80bBf9ed88D6784618a5B1b',
  purchased: false
question from:https://stackoverflow.com/questions/65923995/console-log-bn-did-not-show-the-value

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...