2

I'm trying to assign values passed into a constructor to the instance variables but the assignment doesn't seem to be working and all the values are set to null.

contract MarketMaker {
address iplogic;
address ipxaddr;
function MarketMaker(address _iplogic, address _ipx) {
    iplogic = _iplogic;
    ipxaddr = _ipx;
    log(ipxaddr);
    log(_ipx);
}
event log(address ipx);
function createNewMarket(string prop, uint256 minBet, bool initUtility) onlyIplogic returns (address, address) {
    log(ipxaddr);
    log(iplogic);}

The log works for the constructor and outputs the correct address but when I call createNewMarket the log doesn't display any address and in further testing it can be seen that both ipxaddr and iplogic are null.

I'm not sure why this would be happening.

Thanks in advance.

2
  • Are you sure the transaction really executed and didn't throw an out of gas exception? Also what does onlyIpLogic do?
    – Ismael
    Commented Jul 18, 2017 at 1:02
  • Yeah it goes through and onlyIpLogic is a modifier that checks that the sender is ipLogic Commented Jul 18, 2017 at 1:16

2 Answers 2

0

I've this contract MarketMaker.sol with truffle

contract MarketMaker {
    address iplogic;
    address ipxaddr;

    event log(address ipx);

    function MarketMaker(address _iplogic, address _ipx) {
        iplogic = _iplogic;
        ipxaddr = _ipx;
        log(ipxaddr);
        log(iplogic);
    }

    function createNewMarket(string prop, uint256 minBet, bool initUtility) returns (address, address) {
        log(ipxaddr);
        log(iplogic);
    }
}

And this test MarketMaker.js

var MarketMaker = artifacts.require("./MarketMaker.sol");

contract('MarketMaker', function(accounts) {
  it("Create new market", async function() {
    const instance = await MarketMaker.new(accounts[0], accounts[1]);
    await instance.createNewMarket("Hello!", 1234, false);
    assert.equal(1, 2); // to force display of logged events
  });
});

And the output is as expected

Contract: MarketMaker
1) Create new market

Events emitted during test:
---------------------------

log(ipx: 0x62d24e4cfba4a463e9de6fa14c56b01a1f97c964)
log(ipx: 0xeab0acaca2afeab9e44c3085d2ae9b663fbf4007)
log(ipx: 0x62d24e4cfba4a463e9de6fa14c56b01a1f97c964)
log(ipx: 0xeab0acaca2afeab9e44c3085d2ae9b663fbf4007)

---------------------------


0 passing (64ms)
1 failing

1) Contract: MarketMaker Create new market:
   AssertionError: expected 1 to equal 2
1
  • Interesting. My actual test and contract is slightly more complicated than this but I'll look into why it works in this case and not in the more complex one. Commented Jul 18, 2017 at 19:22
0

As far as I know you can't do events when you create the contract. Just rename the function MarketMaker something else and it works. Maybe someone smarter than I can explain better, but the events are stored in a transactions log and associated with the contract address...and since you're contract doesn't have an address yet, it doesn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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