0

I have a Contract Factory and a sub contract, and now i want to test the newly created sub contract. This one should be pretty simple, I hope.

it("test CoinNewCoin - Test Created Coin ", function (){

    var fromOwner = accounts[0];
    var coinFactory;
    var coinNewCoin;
    return CoinFactory.deployed().then((instance) => {
        coinFactory = instance;
    }).then(() => {
    return coinFactory.getCoinAddress(fromOwner, {from: fromOwner});
    }).then((result) => {
        console.log(result);
    return CoinNewCoin.at(result).then((instance) => {
    }).then((instance) => {
        console.log(instance); // this is the undefined.
        coinNewCoin = instance;
        return coinNewCoin.getAuthorizationKey();
    })
    }).then((result) => {
        console.log(result);
    });
});

edit: scripting updated.

4
  • coinFactory.address on web3 v0.x, and coinFactory._address on web3 v1.x. Sep 22 '18 at 14:49
  • could you expound a bit? maybe something in the form of the newcoin Return? The factory and call to create a coin work fine, now i want to test the created coin, and i have the address of the coin in the result.
    – shaddow
    Sep 22 '18 at 15:09
  • 1
    Maybe change NewCoin.deployed() to NewCoin.at(result). Sep 22 '18 at 15:37
  • (thanks for the help btw), the results Contract: CoinFactory test state √ test CoinFactory (49ms) √ test CoinNewCoin - Create Coin (63ms) 0x74eb9deac37f34457f71adab57fb8bbc6bce3c0a undefined 1) test CoinNewCoin - Test Created Coin > No events were emitted 2 passing (267ms) 1 failing 1) Contract: CoinFactory test state test CoinNewCoin - Test Created Coin : TypeError: Cannot read property 'getAuthorizationKey' of undefined
    – shaddow
    Sep 22 '18 at 16:17
0

return CoinNewCoin.at(result).getAuthorizationKey();

The at(address), was the key. thanks -goodvibration!

it("test CoinNewCoin - Test Created Coin ", function (){

    var fromOwner = accounts[0];
    var coinFactory;
    var coinNewCoin;
    var coinAddress;
    return CoinFactory.deployed().then((instance) => {
        coinFactory = instance;
    }).then(() => {
        return coinFactory.getCoinAddress(fromOwner, {from: fromOwner});
    }).then((result) => {
        return CoinNewCoin.at(result).getAuthorizationKey();
    }).then((result) => {
        var testVal = result.toString().split(",");
        assert.equal("00000000000000000000000000000000",web3.toAscii(testVal[0]), "Coin contract is was not created, fail!")
    });
});

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.