1

I have the following contract:

pragma solidity ^0.4.11;
contract TA2_Transfer {
    address public sender;
    address public receiver;
    uint public packageCount;
    address owner;
    bytes32 name;
    mapping (address => uint) public balances;
    event Transfer(address from, address to, uint objCount);

    function sendToReceiver(address sender, address receiver, uint objCount) 
        payable 
        returns(bool success) 
    {
        balances[sender] -= objCount;
        balances[receiver] += objCount;
        Transfer(sender, receiver, objCount);
        return true;
    }
}
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];
    }
    function sendOrder(address oOrigin, address oShipper, address oCarrier,  address oReceiver, uint oCount) 
        payable 
        returns(bool success) 
    {
        TA2_Transfer t= new TA2_Transfer();
        Bal(1);
        if(!t.sendToReceiver(oOrigin, oCarrier, oCount)) throw;
        if(!t.sendToReceiver(oCarrier, oShipper, oCount)) throw;
        if(!t.sendToReceiver(oShipper, oReceiver, oCount)) throw;
        return true;
    }
}

I am pretty sure That runs in Remix without problems.

But my test script still reports 0 in the Receiver account:

var ShippingOrder = artifacts.require("./ShippingOrder.sol");
contract('ShippingOrder', function(accounts) {
var meta;
var instance;
var  xInt = 10;
var origin = accounts[0];
var shipper = accounts[1];
var carrier = accounts[2];
var receiver = accounts[3];
 it("should put 200 in the first account", function() {
    return ShippingOrder.deployed().then(function(instance) {
      return instance.getBalance.call(origin);
    }).then(function(balance) {
      console.log("Init Complete");
      assert.equal(balance.valueOf(), 200, "200 wasn't in the first account");
    });
  });
 it("should put 10 in the receiver account", function() {
    return ShippingOrder.deployed().then(function(instance) {
      meta = instance;
      //console.log(meta);
      return instance.sendOrder.call(origin, shipper, carrier, receiver, xInt);
    }).then(function(result) {
      console.log("Transfer Complete");
});
});
 it("should have 10 in the receiver account", function() {
    return ShippingOrder.deployed().then(function(instance) {
      meta = instance;
      return meta.getBalance.call(receiver);
    }).then(function(balance) {
      console.log("Receiver Balance: "+balance.valueOf());
      assert.equal(balance.valueOf(), 10, "10 wasn't in the receiver account");
    });
  });
});

1) Contract: ShippingOrder should have 10 in the receiver account:

AssertionError: 10 wasn't in the receiver account: expected '0' to equal 10

What am I missing?

Your Answer

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

Browse other questions tagged or ask your own question.