I wasn't able to get this working using the other "contracts from contracts" examples, so I thought I would post it here. There are two things going wrong:
- The Sent Event in the first contract never emits anything.
- The sendOrder method in the second contract never seems to execute.
Here is the sol file:
pragma solidity ^0.4.11;
contract TA2_Transfer {
address public sender;
address public receiver;
uint public packageCount;
mapping (address => uint) public balances;
event Transfer(address from, address to, uint objCount);
function sendToReceiver(address sender, address receiver, uint256 objCount) payable {
if (balances[sender] < objCount) return;
balances[sender] -= objCount;
balances[receiver] += objCount;
Transfer(sender, receiver, objCount);
}
function getBalance(address _sender) returns(uint) {
return balances[_sender];
}
}
contract ShippingOrder{
TA2_Transfer public t;
address public oOrigin;
address public oShipper;
address public oCarrier;
address public oReceiver;
uint public oCount;
mapping (address => uint) public oBalances;
event Sent(address shipper, address carrier, address receiver, uint objCount);
function ShippingOrder() {
oBalances[tx.origin] = 200;
}
function getBalance(address _sender) returns(uint) {
return oBalances[_sender];
}
function sendOrder(address oOrigin, address oShipper, address oCarrier, address oReceiver, uint256 oCount) payable{
t.sendToReceiver(oOrigin, oShipper, oCount);
t.sendToReceiver(oShipper, oCarrier, oCount);
t.sendToReceiver(oCarrier, oReceiver, oCount);
}
}
And here is the test file:
var ShippingOrder = artifacts.require("./ShippingOrder.sol");
contract('ShippingOrder', function(accounts) {
var meta;
var xInt = 1;
var origin = accounts[0];
var shipper = accounts[1];
var carrier = accounts[2];
var receiver = accounts[3];
it("should put 300 in the first account", function() {
return ShippingOrder.deployed().then(function(instance) {
return instance.getBalance.call(accounts[0]);
}).then(function(balance) {
assert.equal(balance.valueOf(), 200, "300 wasn't in the first account");
});
});
it("should transfer 1 package from Origin to Receiver", function() {
return ShippingOrder.deployed().then(function(instance) {
meta = instance;
return meta.sendOrder.call(origin, shipper, carrier, receiver, xInt);
}).then(function(balance) {
return meta.getBalance.call(origin);
}).then(function(balance) {
origin_balance = balance.toNumber();
return meta.getBalance.call(shipper);
}).then(function(balance) {
shipper_balance = balance.toNumber();
return meta.getBalance.call(carrier);
}).then(function(balance) {
carrier_balance = balance.toNumber();
return meta.getBalance.call(receiver);
}).then(function(balance) {
receiver_balance = balance.toNumber();
assert.equal(origin_balance, 199, "Origin Balance Not 199");
assert.equal(shipper_balance,0, "Shipper Balance Not 0");
assert.equal(carrier_balance, 0, "Carrier Balance Not 0");
assert.equal(receiver_balance, 1, "Receiver Balance Not 1");
});
});
});
Any help would be greatly appreciated... it feels like I am close!!
Frank