2017-10-14 11 views
0

truffle console과 함께 작동하지만 아무런 문제없이 작동하지만 truffle test으로 실패합니다.Solidity (Truffle) : 트뤼플 콘솔에서 잘 작동하지만 트러플 테스트에서는 실패합니다.

contract Geekt { 
    address[] usersByAddress; 

    function registerNewUser(string handle, bytes32 city, bytes32 state, bytes32 country) public returns (bool success) { 
    address newUserAddress = msg.sender; 

    usersByAddress.push(newUserAddress); 

    return true; 
    } 

    function getUsers() public constant returns (address[]) { 
    return usersByAddress; 
    } 
} 

그리고 테스트는 다음과 같습니다 :

코드는

var Geekt = artifacts.require("Geekt"); 

contract('Geekt', function (accounts) { 
    it('should get initial users as empty array', function() { 
    return Geekt.deployed().then(function (instance) { 
     return instance.getUsers.call(); 
    }).then(function (res) { 
     assert.equal(res.length, 0, "Expected empty array after init."); 
    }); 
    }); 

    it('should successfully add user', function() { 
    var geekt; 

    return Geekt.deployed().then(function (instance) { 
     geekt = instance; 

     return geekt.registerNewUser.call("elie222", "London", "State", "UK"); 
    }).then(function (res) { 
     assert.equal(res, true, "Expected registerNewUser to return true."); 
    }).then(function (res) { 
     return geekt.getUsers.call(); 
    }).then(function (res) { 
     // for debugging, but this assert passes: assert.equal(res.length, 0, "Expected array of size 0 after registerNewUser."); 
     // res == [] so the next line fails: 
     assert.equal(res.length, 1, "Expected array of size 1 after registerNewUser."); 
    }); 
    }); 
}); 

이 송로 버섯 콘솔 좋은 작품 :

truffle(development)> Geekt.then(function(instance){return instance.registerNewUser("Tectract","Denver","CO","USA");}) 
{ tx: '0x8eeea303ff9f5ceee56d71fd1265da61991749aa3d5e82db0d2d630a98fd6eb5', 
    receipt: 
    { transactionHash: '0x8eeea303ff9f5ceee56d71fd1265da61991749aa3d5e82db0d2d630a98fd6eb5', 
    transactionIndex: 0, 
    blockHash: '0xf9a0da5ec0aba80a3338781f6d6414ceb43ec0fc023c31649a1cc347a4aba2ea', 
    blockNumber: 14, 
    gasUsed: 24566, 
    cumulativeGasUsed: 24566, 
    contractAddress: null, 
    logs: [] }, 
    logs: [] } 
truffle(development)> Geekt.then(function(instance){return instance.getUsers();}) 
[ '0x1a004a36a6bc9bcde42c6d2b237c6477cf0f535f' ] 

어떻게 이런 일이 일어날 수 있을까? 내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변