2016-12-21 11 views
1

나는 두 개의 계약을 맺고 있는데, 하나의 파일에 Sum.sol이라고 씁니다. sum 계약은 Add contract을 호출합니다. 난 그냥 크로스 - 계약 호출을 테스트하고 싶다. 두 계약을 하나의 파일에 넣지 않으면 트뤼플을 사용하는 합계 컴파일이 실패합니다. 그러나 시험을 치르면 결과가 너무 이상합니다. 어떻게 된 일인지 모르겠습니다. 다음트뤼플을 사용하여 계약 계약을 통해 스마트 계약을 테스트하는 방법은 무엇입니까?

pragma solidity ^0.4.6; 
contract Add{ 
    function sum(uint x, uint y) returns(uint){ 
    return x+y; 
    } 
} 
contract Sum{ 
    function func(uint x, uint y) returns(uint){ 
    Add add = new Add(); 
    uint re = add.sum(x,y); 
    return re; 
    } 
} 

나는 송로 버섯에서 그것을

contract('Sum', function(accounts) { 
    it("should return 5 when add 2 and 3", function() { 
    var sum = Sum.deployed(); 

    return sum.func.call(2,3).then(function(res){ 
     assert.equal(res.valueOf(), 5, "add result is 5"); 

    }); 
    }); 
}); 

을 테스트를 작성하고 송로 버섯을 사용하여 테스트 한 후, 그 결과는 다음과 같습니다

Compiling Sum.sol... 


    Contract: Sum 
    1) should return 5 when add 2 and 3 
    > No events were emitted 


    0 passing (455ms) 
    1 failing 

    1) Contract: Sum should return 5 when add 2 and 3: 
    AssertionError: add result is 5: expected '9.1735649321334958107552852973512799782292704141468709142420585807991067901952e+76' to equal 5 
     at /Users/maiffany/testcoverage/test/add.js:6:14 
     at process._tickDomainCallback   (internal/process/next_tick.js:129:7) 
+0

:

나는 테스트는 다음 코드로 통과있어 – hxmmm

답변

0

내가 왜 테스트 확실하지 않다 3 개월 전 testrpc와 truffle이 많이 바뀌었기 때문에 일하지 않았습니다. 현재 상태에서는 Sum.deployed()이 약속을 반환하기 때문에 테스트가 실패합니다 (직접 함수를 호출 할 수 없음). 이 테스트-RPC 오류가

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

contract('Sum', function(accounts) { 
    it("should return 5 when add 2 and 3", function() { 
    Sum.deployed().then(function(instance){ 
     instance.func.call(2,3).then(function(res){ 
     assert.equal(res.valueOf(), 5, "add result is 5"); 
     }); 
    }); 
    }); 
})