Commit 5a6340b7 authored by didi's avatar didi
Browse files

allow negative settledBalances instead of intermediate stream settlement. refs #2

parent 58111850
......@@ -16,7 +16,7 @@ contract Streem {
* It's just an implementation detail - the "settled" fraction of balance is in no way different or superior to
* the "unsettled" one.
*/
mapping (address => uint256) settledBalances;
mapping (address => int256) settledBalances;
struct Stream {
address sender;
......@@ -41,7 +41,7 @@ contract Streem {
// constructor
function Streem(uint initialSupply) {
owner = msg.sender;
settledBalances[msg.sender] = initialSupply;
settledBalances[msg.sender] = int(initialSupply);
totalSupply = initialSupply;
streams.push(Stream(0,0,0,0)); // empty first element for implicit null-like semantics
}
......@@ -70,8 +70,8 @@ contract Streem {
var settleBal = dt * s.perSecond;
var naiveBal = naiveStreamBalance(s); // remember before manipulating the stream
settledBalances[s.sender] -= settleBal;
settledBalances[s.receiver] += settleBal; // inS.receiver == msg.sender
settledBalances[s.sender] -= int(settleBal);
settledBalances[s.receiver] += int(settleBal); // inS.receiver == msg.sender
// TODO: make sure we really don't need an extra field for this intermediate settlement.
// For correct behaviour, it's irrelevant what the start time of the stream is.
// Applications can rely on the StreamOpened-Event for the UI.
......@@ -101,16 +101,18 @@ contract Streem {
assert(_value > 0 && balanceOf(msg.sender) >= _value);
// if the settled balance doesn't suffice, settle the available funds of the ingoing stream.
if(settledBalances[msg.sender] < _value) {
/*
if(settledBalances[msg.sender] < int(_value)) {
var inS = getInStreamOf(msg.sender);
settleStream(inS);
// lets check again! TODO: once the logic was validated / proofed, this checks should be superfluous
assert(balanceOf(msg.sender) >= _value);
}
*/
settledBalances[msg.sender] -= _value;
settledBalances[_to] += _value;
settledBalances[msg.sender] -= int(_value);
settledBalances[_to] += int(_value);
Transfer(msg.sender, _to, _value);
}
......@@ -157,9 +159,12 @@ contract Streem {
var inS = getInStreamOf(s.sender);
uint256 isb = exists(inS) ? streamBalance(inS) : 0;
uint sb = settledBalances[s.sender];
int sb = settledBalances[s.sender];
return min(osb, sb + isb);
// TODO: Proof needed
assert(sb + int(isb) >= 0);
return min(osb, uint(sb + int(isb)));
}
// this balance function can return a negative value if an outgoing stream went "under water"
......@@ -194,7 +199,8 @@ contract Streem {
uint256 outStreamBal = exists(outS) ? streamBalance(outS) : 0;
// TODO: check overflow before casting
return settledBalances[_owner] + inStreamBal - outStreamBal;
assert(settledBalances[_owner] + int(inStreamBal) - int(outStreamBal) >= 0);
return uint(settledBalances[_owner] + int(inStreamBal) -int(outStreamBal));
}
// TODO: implement the empty function?
......@@ -205,7 +211,7 @@ contract Streem {
// TODO: this is just for the test token. Issuance mechanism for mainnet token to be decided.
function dev_issueTo(address receiver, uint256 amount) {
require(msg.sender == owner);
settledBalances[receiver] += amount;
settledBalances[receiver] += int(amount);
totalSupply += amount;
}
......@@ -217,7 +223,7 @@ contract Streem {
inStreamPtrs[msg.sender] = 0;
if(msg.sender == owner) {
settledBalances[msg.sender] = totalSupply;
settledBalances[msg.sender] = int(totalSupply);
delete streams;
streams.push(Stream(0,0,0,0));
......
......@@ -207,15 +207,15 @@ const contract = {
"name": "dev_inStream",
"outputs": [
{
"name": "addr",
"name": "",
"type": "address"
},
{
"name": "speed",
"name": "",
"type": "uint256"
},
{
"name": "age",
"name": "",
"type": "uint256"
}
],
......@@ -317,7 +317,7 @@ const contract = {
"type": "event"
}
],
"unlinked_binary": "0x6060604052341561000f57600080fd5b6040516020806110d8833981016040528080519150505b60018054600160a060020a03191633600160a060020a03169081178255600090815260026020526040812083905582905560058054909181016100698382610103565b916000526020600020906004020160005b60806040519081016040908152600080835260208301819052908201819052606082015291905081518154600160a060020a031916600160a060020a03919091161781556020820151600182018054600160a060020a031916600160a060020a039290921691909117905560408201518160020155606082015181600301555050505b5061017b565b81548183558181151161012f5760040281600402836000526020600020918201910161012f9190610135565b5b505050565b61017891905b80821115610174578054600160a060020a031990811682556001820180549091169055600060028201819055600382015560040161013b565b5090565b90565b610f4e8061018a6000396000f300606060405236156100d85763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100dd57806318160ddd14610168578063313ce5671461018d5780635cc8ce33146101b657806364a80c0c146101db57806370a08231146101ff5780637ae2b5c71461023057806395d89b411461025b5780639dad9382146102e6578063a1365fda146102fb578063a9059cbb14610320578063e13e2ecf14610344578063e61b959e14610368578063e8f88890146103b1578063f408ebe9146103fa575b600080fd5b34156100e857600080fd5b6100f061040f565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561012d5780820151818401525b602001610114565b50505050905090810190601f16801561015a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561017357600080fd5b61017b610446565b60405190815260200160405180910390f35b341561019857600080fd5b6101a061044c565b60405160ff909116815260200160405180910390f35b34156101c157600080fd5b61017b610451565b60405190815260200160405180910390f35b34156101e657600080fd5b6101fd600160a060020a036004351660243561046e565b005b341561020a57600080fd5b61017b600160a060020a03600435166105f8565b60405190815260200160405180910390f35b341561023b57600080fd5b61017b60043560243561076c565b60405190815260200160405180910390f35b341561026657600080fd5b6100f0610786565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561012d5780820151818401525b602001610114565b50505050905090810190601f16801561015a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156102f157600080fd5b6101fd6107bd565b005b341561030657600080fd5b61017b6108d4565b60405190815260200160405180910390f35b341561032b57600080fd5b6101fd600160a060020a03600435166024356108db565b005b341561034f57600080fd5b6101fd600160a060020a03600435166024356109ec565b005b341561037357600080fd5b61037b610a30565b6040518084600160a060020a0316600160a060020a03168152602001838152602001828152602001935050505060405180910390f35b34156103bc57600080fd5b61037b610a6a565b6040518084600160a060020a0316600160a060020a03168152602001838152602001828152602001935050505060405180910390f35b341561040557600080fd5b6101fd610aa1565b005b60408051908101604052600681527f53747265656d0000000000000000000000000000000000000000000000000000602082015281565b60005481565b600081565b600160a060020a0333166000908152600260205260409020545b90565b60006104bc61047c33610bad565b608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610bef565b156104c357fe5b60006104ce336105f8565b10156104d657fe5b6001600580548060010182816104ec9190610e85565b916000526020600020906004020160005b60806040519081016040908152600160a060020a03338116835289166020830152810187905242606082015291905081518154600160a060020a031916600160a060020a03919091161781556020820151600182018054600160a060020a031916600160a060020a0392909216919091179055604082015181600201556060820151600391820155600160a060020a03338116600081815260209384526040808220979096039687905591891680835260049093529084902085905593945092917f4baaa557c21346b70bdc9482890b5d7e315f6a2123611e74004857ebecde0686915085905190815260200160405180910390a35b505050565b600080600080600061060986610c00565b935061064f84608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610bef565b61065a57600061069e565b61069e84608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610c42565b5b92506106aa86610bad565b91506106f082608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610bef565b6106fb57600061073f565b61073f82608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610c42565b5b600160a060020a0387166000908152600260205260409020548401819003955090505b50505050919050565b600081831061077b578161077d565b825b90505b92915050565b60408051908101604052600381527f5354520000000000000000000000000000000000000000000000000000000000602082015281565b60008060006107cb33610bad565b925061081183608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610bef565b151561081957fe5b61085d83608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610d38565b60018501546002860154929450909250600160a060020a039081169133909116907f96c5271ec05cb2683bdc50cf109341f5a4e45b02907df1c23a8855bddbe030a190858560405180848152602001838152602001828152602001935050505060405180910390a36105f333610e06565b5b505050565b6005545b90565b600080821180156108f45750816108f1336105f8565b10155b15156108fc57fe5b600160a060020a033316600090815260026020526040902054829010156109805761092633610c00565b905061096c81608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610d38565b505081610978336105f8565b101561098057fe5b5b600160a060020a033381166000818152600260205260408082208054879003905592861680825290839020805486019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a35b505050565b60015433600160a060020a03908116911614610a0757600080fd5b600160a060020a03821660009081526002602052604081208054830190558054820190555b5050565b600080600080610a3f33610bad565b600181015460028201546003830154600160a060020a03909216965094504203925090505b50909192565b600080600080610a7933610c00565b805460028201546003830154600160a060020a03909216965094504203925090505b50909192565b600160a060020a0333811660008181526002602090815260408083208390556003825280832083905560049091528120556001549091161415610baa5760008054600160a060020a033316825260026020526040822055610b0490600590610eb7565b6005805460018101610b168382610e85565b916000526020600020906004020160005b60806040519081016040908152600080835260208301819052908201819052606082015291905081518154600160a060020a031916600160a060020a03919091161781556020820151600182018054600160a060020a031916600160a060020a039290921691909117905560408201518160020155606082015181600301555050505b5b565b600160a060020a038116600090815260036020526040812054600580549091908110610bd557fe5b906000526020600020906004020160005b5090505b919050565b60008160600151151590505b919050565b600160a060020a038116600090815260046020526040812054600580549091908110610bd557fe5b906000526020600020906004020160005b5090505b919050565b6000806000806000610c5386610e6e565b9350610c5f8651610c00565b9250610ca583608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610bef565b610cb0576000610cf4565b610cf483608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610c42565b5b9150600260008751600160a060020a0316600160a060020a03168152602001908152602001600020549050610d2c8483830161076c565b94505b50505050919050565b600080600080600080610d4a87610c42565b9350866040015184811515610d5b57fe5b049250866040015183029150610d7087610e6e565b905081600260008951600160a060020a0316600160a060020a031681526020019081526020016000206000828254039250508190555081600260008960200151600160a060020a031681526020810191909152604001600020805490910190558260608801818151019052504260608801511115610dea57fe5b80821115610df457fe5b81828203955095505b50505050915091565b600160a060020a0381166000908152600360205260409020546005805482908110610e2d57fe5b906000526020600020906004020160005b508054600160a060020a0319908116825560018201805490911690556000600282018190556003909101555b5050565b60008160400151826060015142030290505b919050565b8154818355818115116105f3576004028160040283600052602060002091820191016105f39190610edc565b5b505050565b5080546000825560040290600052602060002090810190610ed89190610edc565b5b50565b61046b91905b80821115610f1b578054600160a060020a0319908116825560018201805490911690556000600282018190556003820155600401610ee2565b5090565b905600a165627a7a72305820945979f7af2eb1e6a377d69b2a7728655b89376d2d2d4cd29884bb7c5f68ca4a0029",
"unlinked_binary": "0x6060604052341561000f57600080fd5b60405160208061107f833981016040528080519150505b60018054600160a060020a03191633600160a060020a03169081178255600090815260026020526040812083905582905560058054909181016100698382610103565b916000526020600020906004020160005b60806040519081016040908152600080835260208301819052908201819052606082015291905081518154600160a060020a031916600160a060020a03919091161781556020820151600182018054600160a060020a031916600160a060020a039290921691909117905560408201518160020155606082015181600301555050505b5061017b565b81548183558181151161012f5760040281600402836000526020600020918201910161012f9190610135565b5b505050565b61017891905b80821115610174578054600160a060020a031990811682556001820180549091169055600060028201819055600382015560040161013b565b5090565b90565b610ef58061018a6000396000f300606060405236156100d85763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100dd57806318160ddd14610168578063313ce5671461018d5780635cc8ce33146101b657806364a80c0c146101db57806370a08231146101ff5780637ae2b5c71461023057806395d89b411461025b5780639dad9382146102e6578063a1365fda146102fb578063a9059cbb14610320578063e13e2ecf14610344578063e61b959e14610368578063e8f88890146103b1578063f408ebe9146103fa575b600080fd5b34156100e857600080fd5b6100f061040f565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561012d5780820151818401525b602001610114565b50505050905090810190601f16801561015a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561017357600080fd5b61017b610446565b60405190815260200160405180910390f35b341561019857600080fd5b6101a061044c565b60405160ff909116815260200160405180910390f35b34156101c157600080fd5b61017b610451565b60405190815260200160405180910390f35b34156101e657600080fd5b6101fd600160a060020a036004351660243561046e565b005b341561020a57600080fd5b61017b600160a060020a03600435166105f8565b60405190815260200160405180910390f35b341561023b57600080fd5b61017b600435602435610794565b60405190815260200160405180910390f35b341561026657600080fd5b6100f06107ae565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561012d5780820151818401525b602001610114565b50505050905090810190601f16801561015a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156102f157600080fd5b6101fd6107e5565b005b341561030657600080fd5b61017b6108fc565b60405190815260200160405180910390f35b341561032b57600080fd5b6101fd600160a060020a0360043516602435610903565b005b341561034f57600080fd5b6101fd600160a060020a036004351660243561098d565b005b341561037357600080fd5b61037b6109d1565b6040518084600160a060020a0316600160a060020a03168152602001838152602001828152602001935050505060405180910390f35b34156103bc57600080fd5b61037b610a0b565b6040518084600160a060020a0316600160a060020a03168152602001838152602001828152602001935050505060405180910390f35b341561040557600080fd5b6101fd610a42565b005b60408051908101604052600681527f53747265656d0000000000000000000000000000000000000000000000000000602082015281565b60005481565b600081565b600160a060020a0333166000908152600260205260409020545b90565b60006104bc61047c33610b4e565b608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610b90565b156104c357fe5b60006104ce336105f8565b10156104d657fe5b6001600580548060010182816104ec9190610e2c565b916000526020600020906004020160005b60806040519081016040908152600160a060020a03338116835289166020830152810187905242606082015291905081518154600160a060020a031916600160a060020a03919091161781556020820151600182018054600160a060020a031916600160a060020a0392909216919091179055604082015181600201556060820151600391820155600160a060020a03338116600081815260209384526040808220979096039687905591891680835260049093529084902085905593945092917f4baaa557c21346b70bdc9482890b5d7e315f6a2123611e74004857ebecde0686915085905190815260200160405180910390a35b505050565b600080600080600061060986610ba1565b935061064f84608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610b90565b61065a57600061069e565b61069e84608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610be3565b5b92506106aa86610b4e565b91506106f082608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610b90565b6106fb57600061073f565b61073f82608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610be3565b5b600160a060020a038716600090815260026020526040812054919250908401829003121561076a57fe5b600160a060020a038616600090815260026020526040902054830181900394505b50505050919050565b60008183106107a357816107a5565b825b90505b92915050565b60408051908101604052600381527f5354520000000000000000000000000000000000000000000000000000000000602082015281565b60008060006107f333610b4e565b925061083983608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610b90565b151561084157fe5b61088583608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610cdf565b60018501546002860154929450909250600160a060020a039081169133909116907f96c5271ec05cb2683bdc50cf109341f5a4e45b02907df1c23a8855bddbe030a190858560405180848152602001838152602001828152602001935050505060405180910390a36105f333610dad565b5b505050565b6005545b90565b60008111801561091b575080610918336105f8565b10155b151561092357fe5b600160a060020a033381166000818152600260205260408082208054869003905592851680825290839020805485019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9084905190815260200160405180910390a35b5050565b60015433600160a060020a039081169116146109a857600080fd5b600160a060020a03821660009081526002602052604081208054830190558054820190555b5050565b6000806000806109e033610b4e565b600181015460028201546003830154600160a060020a03909216965094504203925090505b50909192565b600080600080610a1a33610ba1565b805460028201546003830154600160a060020a03909216965094504203925090505b50909192565b600160a060020a0333811660008181526002602090815260408083208390556003825280832083905560049091528120556001549091161415610b4b5760008054600160a060020a033316825260026020526040822055610aa590600590610e5e565b6005805460018101610ab78382610e2c565b916000526020600020906004020160005b60806040519081016040908152600080835260208301819052908201819052606082015291905081518154600160a060020a031916600160a060020a03919091161781556020820151600182018054600160a060020a031916600160a060020a039290921691909117905560408201518160020155606082015181600301555050505b5b565b600160a060020a038116600090815260036020526040812054600580549091908110610b7657fe5b906000526020600020906004020160005b5090505b919050565b60008160600151151590505b919050565b600160a060020a038116600090815260046020526040812054600580549091908110610b7657fe5b906000526020600020906004020160005b5090505b919050565b6000806000806000610bf486610e15565b9350610c008651610ba1565b9250610c4683608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610b90565b610c51576000610c95565b610c9583608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610be3565b5b9150600260008751600160a060020a03168152602081019190915260400160009081205491508282011215610cc757fe5b610cd384838301610794565b94505b50505050919050565b600080600080600080610cf187610be3565b9350866040015184811515610d0257fe5b049250866040015183029150610d1787610e15565b905081600260008951600160a060020a0316600160a060020a031681526020019081526020016000206000828254039250508190555081600260008960200151600160a060020a031681526020810191909152604001600020805490910190558260608801818151019052504260608801511115610d9157fe5b80821115610d9b57fe5b81828203955095505b50505050915091565b600160a060020a0381166000908152600360205260409020546005805482908110610dd457fe5b906000526020600020906004020160005b508054600160a060020a0319908116825560018201805490911690556000600282018190556003909101555b5050565b60008160400151826060015142030290505b919050565b8154818355818115116105f3576004028160040283600052602060002091820191016105f39190610e83565b5b505050565b5080546000825560040290600052602060002090810190610e7f9190610e83565b5b50565b61046b91905b80821115610ec2578054600160a060020a0319908116825560018201805490911690556000600282018190556003820155600401610e89565b5090565b905600a165627a7a72305820d00c5aac227632ff138d1a4fa835789fdf6e37adb194ce535e3394712417a6790029",
"networks": {
"1500075197859": {
"events": {
......@@ -982,10 +982,10 @@ const contract = {
}
},
"links": {},
"address": "0x58c5cd125283b58476af87fe8c53c11ba0f7a735",
"updated_at": 1502035108745
"address": "0xc5dc2ba3aee4b8c2cdc659a27118a5c5317705dd",
"updated_at": 1502119211001
}
},
"schema_version": "0.0.5",
"updated_at": 1502035108745
"updated_at": 1502119211001
}
\ No newline at end of file
......@@ -42,15 +42,16 @@ function initContract() {
})
}
const nrTestAccounts = 5
// for f it expects a function which takes an address as argument
function execForTestAccs(f) {
for(let i=0; i<3; i++) {
function applyForTestAccs(f) {
for(let i=0; i<nrTestAccounts; i++) {
f(web3.eth.accounts[i])
}
}
function updateDetailTable() {
execForTestAccs( (addr, i) => {
applyForTestAccs( (addr, i) => {
streem.balanceOf(addr, (err, ret) => {
document.getElementById(`${addr}-bal`).innerHTML = web3.toDecimal(ret)
})
......@@ -114,6 +115,7 @@ function initTableRowFor(addr) {
table.appendChild(row)
}
var accs = []
window.addEventListener('load', () => {
console.log('window loaded')
......@@ -135,11 +137,12 @@ window.addEventListener('load', () => {
keepBlockchainAlive(5) // testrpc seems to have a lower limit of 5 sec
}
if(web3.eth.accounts.length < 3) {
if(web3.eth.accounts.length < nrTestAccounts) {
alert("ERROR: less than 3 accounts available")
}
execForTestAccs( addr => initTableRowFor(addr) )
applyForTestAccs(addr => accs.push(addr) ) // for convenience in JS console
applyForTestAccs(addr => initTableRowFor(addr) )
})
// ############################################################################
......@@ -147,7 +150,7 @@ window.addEventListener('load', () => {
// closes the outgoing streams of the test accounts
// this will throw an expection for accounts without outstream. Doesn't hurt us.
function close() {
execForTestAccs( addr => {streem.closeStream({from: addr, gas: 200000}, (err, ret) => {
applyForTestAccs(addr => {streem.closeStream({from: addr, gas: 200000}, (err, ret) => {
if(err) console.log(`closeStream failed for ${addr}`)
})})
}
......@@ -160,38 +163,63 @@ function freeze() {
}
function reset() {
execForTestAccs( addr => streem.dev_reset( {from: addr, gas: 2000000} )) //note that this is more gas!
console.log('resetting...')
applyForTestAccs(addr => streem.dev_reset( {from: addr, gas: 2000000} )) //note that this is more gas!
}
// test: balances are correct
function test1() {
// stream1: speed 1 from addr0 to addr1
console.log('starting stream1')
console.log('open stream1: speed 1 from addr0 to addr1')
streem.openStream(web3.eth.accounts[1], 1, {from: web3.eth.accounts[0], gas: 200000})
// stream2: speed 1 from addr1 to addr2
console.log('starting stream2')
console.log('open stream2: speed 1 from addr1 to addr2')
streem.openStream(web3.eth.accounts[2], 1, {from: web3.eth.accounts[1], gas: 200000})
}
// test: dryed out stream
function test1a() {
// ...
// close stream1
// wait 5
// close stream2
console.log('closing stream1')
streem.closeStream({from: web3.eth.accounts[0], gas: 200000})
console.log('waiting 20 sec...')
setTimeout( () => {
console.log('closing stream2')
streem.closeStream({from: web3.eth.accounts[1], gas: 200000})
}, 20000)
// assert: bal(addr1) is 0, stream2 stalls
}
// test: underfunded stream
function test1b() {
// ...
test1()
// stream with speed 1 from addr0 to addr1
// stream with speed 2 from addr1 to addr2
// wait 5
function test2() {
console.log('open stream1: speed 1 from addr0 to addr1')
streem.openStream(web3.eth.accounts[1], 1, {from: web3.eth.accounts[0], gas: 200000})
console.log('open stream2: speed 2 from addr1 to addr2')
streem.openStream(web3.eth.accounts[2], 2, {from: web3.eth.accounts[1], gas: 200000})
// wait 10
// assert: bal(addr1) is 0, lab(addr2) is 5
// close stream1
// close stream2
// assert: bal(addr1) is 0, lab(addr2) is 5
}
function test3() {
console.log('open stream1: speed 1 from addr0 to addr1')
streem.openStream(web3.eth.accounts[1], 1, {from: web3.eth.accounts[0], gas: 200000})
console.log('open stream2: speed 1 from addr1 to addr0')
streem.openStream(web3.eth.accounts[0], 1, {from: web3.eth.accounts[1], gas: 200000})
}
function test4() {
console.log('open stream1: speed 1 from addr0 to addr1')
streem.openStream(web3.eth.accounts[1], 1, {from: web3.eth.accounts[0], gas: 200000})
console.log('open stream2: speed 1 from addr1 to addr2')
streem.openStream(web3.eth.accounts[2], 1, {from: web3.eth.accounts[1], gas: 200000})
console.log('open stream3: speed 1 from addr2 to addr0')
streem.openStream(web3.eth.accounts[0], 1, {from: web3.eth.accounts[2], gas: 200000})
}
\ No newline at end of file
......@@ -35,9 +35,11 @@ Size of streams array: <span id="nrstreams">-</span><br>
<hr>
<button id="test1">Test1</button><br>
<button id="test2">Test1a</button><br>
<button id="test3">Test1b</button><br>
<button id="test1">Test1: open A->B (1), open B->C (1)</button><br>
<button id="test1a">Test1a: close A->B, wait 20, close B->C</button><br>
<button id="test2">Test2: open A->B (1), open B->C (2)</button><br>
<button id="test3">Test3: open A->B (1), open B->A (1)</button><br>
<button id="test4">Test4: open A->B (1), open B->C (1), open C->A (1)</button><br>
<script type="text/javascript" src="lib/web3.js"></script>
<script type="text/javascript" src="js/streem_contract.js"></script>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment