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

allEvents fails to capture both events emitted by solidity contract function #146

Open
timothywangdev opened this issue Nov 8, 2018 · 7 comments
Labels
bug Something isn't working

Comments

@timothywangdev
Copy link

timothywangdev commented Nov 8, 2018

"loom-js": "^1.30.2"
solidity ^0.4.23
latest loom installed from

curl https://raw.githubusercontent.com/loomnetwork/loom-sdk-documentation/master/scripts/get_loom.sh | sh
this.repSysInstance.events.allEvents().on('data', this.onEvent)

This one does not catch both events (Delegate, UpdateDelegation) emitted from a function. Only the first event emiited (UpdateDelegation) is caught.

We have to add the following code to make it work

this.repSysInstance.events.Delegate({},(error, event) => { ... }) 

Related to #82

It turned out using the above code did not work as well, we did a little experiment as follows:

  • solidity code
event Test(uint num);
function test(uint k) external {
        for (uint i = 0; i < k; i++) {
            emit Test(i);
        }
    }
  • truffle test script
let rv = await contract.test(2)
console.log(rv)
  • Contract event listener js script:
this.contract.events.Test({fromBlock: 0},
                                        (error, event) => {
                                          console.log(event)
                                        })

Results

Only one event received in our event listener yet 2 events showed up in the test script log:

{ tx: '0x32c257bb576102c8e1cfde8c96efb2cce36aebe14250ff4edf271b599a93e5bb',
  receipt: 
   { transactionHash: '0x32c257bb576102c8e1cfde8c96efb2cce36aebe14250ff4edf271b599a93e5bb',
     transactionIndex: 1,
     blockHash: '0x77338f1bd79aadf62bea957e7a6bd807a22dc5e6',
     blockNumber: 242421,
     contractAddress: '0x36d2b3675607f48e03dd3fdde3e34e5ad7d74397',
     gasUsed: 0,
     cumulativeGasUsed: 0,
     logs: [ [Object], [Object] ],
     status: '0x1' },
  logs: 
   [ { logIndex: 0,
       address: '0x36d2b3675607f48e03dd3fdde3e34e5ad7d74397',
       blockHash: '0x77338f1bd79aadf62bea957e7a6bd807a22dc5e6',
       blockNumber: 242421,
       transactionHash: '0x32c257bb576102c8e1cfde8c96efb2cce36aebe14250ff4edf271b599a93e5bb',
       transactionIndex: 1,
       type: 'mined',
       event: 'Test',
       args: [Object] },
     { logIndex: 1,
       address: '0x36d2b3675607f48e03dd3fdde3e34e5ad7d74397',
       blockHash: '0x77338f1bd79aadf62bea957e7a6bd807a22dc5e6',
       blockNumber: 242421,
       transactionHash: '0x32c257bb576102c8e1cfde8c96efb2cce36aebe14250ff4edf271b599a93e5bb',
       transactionIndex: 1,
       type: 'mined',
       event: 'Test',
       args: [Object] } ] }

@eduardonunesp
Copy link
Contributor

@timothywangdev what is the version of the loom sdk, loom version

@timothywangdev
Copy link
Author

timothywangdev commented Nov 9, 2018

@eduardonunesp
loom: 1.0.0+b478
"loom-truffle-provider": "^0.8.0"
"web3": "^1.0.0-beta.33"

@such
Copy link

such commented Nov 23, 2018

Hello,
I'm having the same issue.
This function is really suspicious in LoomProvider.ts:

private _onWebSocketMessage(msgEvent: IChainEventArgs) {
    if (msgEvent.data && msgEvent.id !== '0') {
      log(`Socket message arrived ${JSON.stringify(msgEvent)}`)
      this.notificationCallbacks.forEach((callback: Function) => {
        const JSONRPCResult = {
          jsonrpc: '2.0',
          method: 'eth_subscription',
          params: {
            subscription: msgEvent.id,
            result: {
              transactionHash: bytesToHexAddrLC(msgEvent.transactionHashBytes),
              logIndex: '0x0',
              transactionIndex: '0x0',
              blockHash: '0x0',
              blockNumber: '0x0',
              address: msgEvent.contractAddress.local.toString(),
              type: 'mined',
              data: bytesToHexAddrLC(msgEvent.data),
              topics: msgEvent.topics
            }
          }
        }

        callback(JSONRPCResult)
      })
    }
  }

It also hardcodes blockNumber: '0x0' which leads to unexpected behaviour.

@timothywangdev
Copy link
Author

timothywangdev commented Nov 26, 2018

Can we get some updates on the fix? Thanks. @eduardonunesp

@mattkanwisher
Copy link
Contributor

hey @timothywangdev we are heads down for our upcoming plasmachain launch, this is likely 2 weeks off. I'm sorry we are a bit swamped. Can you give us some background on what you are trying to build?

@eduardonunesp
Copy link
Contributor

Hi @timothywangdev thanks for your report, could you please confirm if the test add on this PR #194 is compatible with your issue

@eduardonunesp
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants