2

I have the following contract code:

contract ShippingOrder{
    address public oOrigin;
    address public oShipper;
    address public oCarrier;
    address public oReceiver;
    mapping (address => uint) public obalances;
    event Bal (uint balance);
    function ShippingOrder() {
        obalances[tx.origin] = 200;
    }
    function getBalance(address sender) returns(uint) {
        Bal(obalances[sender]);
        return obalances[sender];
    }

the getBalance function runs and returns a balance, but the Bal event never emits...

1

Your code seems to work perfectly and the event got fired.

enter image description here

2
  • 1
    Sorry I should have been more specific... I don't see the emitted events when I run truffle test. I seem to recall that the emitted events used to display in truffle. – Frank Blau Jul 13 '17 at 12:57
  • so edit your question and add more elements in order to help you – Badr Bellaj Jul 13 '17 at 13:00
1

From your comment I guess that you're asking about Truffle specifically. Currently Truffle tests only show events in the output log if a test fails. Therefore you could add an assert.isTrue(false); inside any it-block in which you call a smart contract function that raises event and you'll see the event in the output log.

1
  • It doesn't always work. It's truly bizarre about when it works and when it doesn't. In fact it normally doesn't. Also doesn't work when using --show-events. – JohnAllen Dec 4 '17 at 4:30

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.