When I test my selling event in truffle.So, the following error comes:- The solidity code is :-

event Sell(address _buyer, uint256 _amount);
// Buy token
function buyTokens(uint256 _numberOfTokens) public payable {

    // Keep track of tokenSold
    tokensSold += _numberOfTokens;

    // Trigger Sell Event
     emit Sell(msg.sender,_numberOfTokens);


And my test.js code like this:-

it('facalities to token buying',function(){

// Keep track of number of token sold
return DappTokenSale.deployed().then(function(instance){
        tokenSaleInstance = instance;
        numberOfTokens = 10;
        return tokenSaleInstance.buyTokens(numberOfTokens,{form:buyer, value:numberOfTokens * tokenPrice})  

    assert.equal(receipt.logs.length,1,'triggers one event');
        assert.equal(receipt.logs[0].event,'Sell','Should be the "Sell" event');
        assert.equal(receipt.logs[0].args._buyer,buyer,'logs the accounts that purchase tokens');
        assert.equal(receipt.logs[0].args._amount,numberOfTokens,'logs the number of token purchase');
        return tokenSaleInstance.tokensSold();
    assert.equal(amount.toNumber(),numberOfTokens,'increments the number of token sold');
    // Try to buy the token different form the ether value
    return return tokenSaleInstance.buyTokens(numberOfTokens,{form:buyer, value:1});
        assert(error.message.indexOf('revert') >=0,'msg.value must equal number of tokens in wai');


When I go Ubuntu terminal and hit the command:- truffle test

So this Error comes:-

AssertionError: logs the accounts that purchase tokens: expected '0x35374bce8edeb31f662944dd8bd1f09dd38a6fea' to equal '0x6297dfc898fa47fe7e2592a79ee01c4c207bdc77'.

So,what I mistake in this test.js line:

   assert.equal(receipt.logs[0].args._buyer,buyer,'logs the accounts that purchase tokens');

When I test it on terminal with truffle console command:-

tokenSellInstance.buyTokens(numberOfTokens,{form:web3.eth.accounts[2], value:10 * 1000000000000000})

So, result look like this:-

{ tx: '0x26d8ae437d64c6449d6b1378384441beecf4df8997ad66cb9dafaacb919ac8f1',
   { transactionHash: '0x26d8ae437d64c6449d6b1378384441beecf4df8997ad66cb9dafaacb919ac8f1',
     transactionIndex: 0,
     blockHash: '0xfd74a32ae0629303283fb23b408ef11f6a2d74b110d8c5d65ee630a2191e2c03',
     blockNumber: 52,
     gasUsed: 43196,
     cumulativeGasUsed: 43196,
     contractAddress: null,
     logs: [ [Object] ],
     status: '0x01',
     logsBloom: '0x00000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000001000000000000000000000010000000000000000000000000000000000000004000000000' },
   [ { logIndex: 0,
       transactionIndex: 0,
       transactionHash: '0x26d8ae437d64c6449d6b1378384441beecf4df8997ad66cb9dafaacb919ac8f1',
       blockHash: '0xfd74a32ae0629303283fb23b408ef11f6a2d74b110d8c5d65ee630a2191e2c03',
       blockNumber: 52,
       address: '0x6ea8d6042826ca0b0f504384f1b7fd1e89a84efa',
       type: 'mined',
       event: 'Sell',
       args: [Object] } ] }

So why this error comes.Please tell me my mistake as soon as.

  • 1
    can you post the code that fires the event and how you make the call – mirg Apr 25 '18 at 6:37
  • Yes solidity code is :-Trigger sell event I call this this way Sell(msg.sender,_numberOfTokens); – Anupam Jain Apr 25 '18 at 6:59
  • I know, but is not posted. If you want some help compete the question the information you provided are not enough to do some analysis – mirg Apr 25 '18 at 7:01
  • Hello mirg I updated my question.You can see now – Anupam Jain Apr 25 '18 at 7:12
  • 1
    Not quite sure if this really causes the issue, but you misspelled from in every call to your contract...so maybe try to fix that and go again – Kai Kälberer Apr 26 '18 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.