Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
didi
github_repo_test
Commits
5a6340b7
Commit
5a6340b7
authored
Aug 07, 2017
by
didi
Browse files
allow negative settledBalances instead of intermediate stream settlement. refs #2
parent
58111850
Changes
4
Hide whitespace changes
Inline
Side-by-side
backend/contracts/Streem.sol
View file @
5a6340b7
...
...
@@ -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
=>
u
int256
)
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
;
u
int
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
));
...
...
frontend/js/streem_contract.js
View file @
5a6340b7
...
...
@@ -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
"
:
"
0x6060604052341561000f57600080fd5b6040516020806110
d8
833981016040528080519150505b60018054600160a060020a03191633600160a060020a03169081178255600090815260026020526040812083905582905560058054909181016100698382610103565b916000526020600020906004020160005b60806040519081016040908152600080835260208301819052908201819052606082015291905081518154600160a060020a031916600160a060020a03919091161781556020820151600182018054600160a060020a031916600160a060020a039290921691909117905560408201518160020155606082015181600301555050505b5061017b565b81548183558181151161012f5760040281600402836000526020600020918201910161012f9190610135565b5b505050565b61017891905b80821115610174578054600160a060020a031990811682556001820180549091169055600060028201819055600382015560040161013b565b5090565b90565b610
f4e
8061018a6000396000f300606060405236156100d85763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100dd57806318160ddd14610168578063313ce5671461018d5780635cc8ce33146101b657806364a80c0c146101db57806370a08231146101ff5780637ae2b5c71461023057806395d89b411461025b5780639dad9382146102e6578063a1365fda146102fb578063a9059cbb14610320578063e13e2ecf14610344578063e61b959e14610368578063e8f88890146103b1578063f408ebe9146103fa575b600080fd5b34156100e857600080fd5b6100f061040f565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561012d5780820151818401525b602001610114565b50505050905090810190601f16801561015a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561017357600080fd5b61017b610446565b60405190815260200160405180910390f35b341561019857600080fd5b6101a061044c565b60405160ff909116815260200160405180910390f35b34156101c157600080fd5b61017b610451565b60405190815260200160405180910390f35b34156101e657600080fd5b6101fd600160a060020a036004351660243561046e565b005b341561020a57600080fd5b61017b600160a060020a03600435166105f8565b60405190815260200160405180910390f35b341561023b57600080fd5b61017b6004356024356107
6c
565b60405190815260200160405180910390f35b341561026657600080fd5b6100f06107
86
565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561012d5780820151818401525b602001610114565b50505050905090810190601f16801561015a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156102f157600080fd5b6101fd6107
bd
565b005b341561030657600080fd5b61017b6108
d4
565b60405190815260200160405180910390f35b341561032b57600080fd5b6101fd600160a060020a0360043516602435610
8db
565b005b341561034f57600080fd5b6101fd600160a060020a03600435166024356109
ec
565b005b341561037357600080fd5b61037b610
a30
565b6040518084600160a060020a0316600160a060020a03168152602001838152602001828152602001935050505060405180910390f35b34156103bc57600080fd5b61037b610a
6a
565b6040518084600160a060020a0316600160a060020a03168152602001838152602001828152602001935050505060405180910390f35b341561040557600080fd5b6101fd610a
a1
565b005b60408051908101604052600681527f53747265656d0000000000000000000000000000000000000000000000000000602082015281565b60005481565b600081565b600160a060020a0333166000908152600260205260409020545b90565b60006104bc61047c33610b
ad
565b608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610b
ef
565b156104c357fe5b60006104ce336105f8565b10156104d657fe5b6001600580548060010182816104ec9190610e
85
565b916000526020600020906004020160005b60806040519081016040908152600160a060020a03338116835289166020830152810187905242606082015291905081518154600160a060020a031916600160a060020a03919091161781556020820151600182018054600160a060020a031916600160a060020a0392909216919091179055604082015181600201556060820151600391820155600160a060020a03338116600081815260209384526040808220979096039687905591891680835260049093529084902085905593945092917f4baaa557c21346b70bdc9482890b5d7e315f6a2123611e74004857ebecde0686915085905190815260200160405180910390a35b505050565b600080600080600061060986610
c00
565b935061064f84608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610b
ef
565b61065a57600061069e565b61069e84608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610
c42
565b5b92506106aa86610b
ad
565b91506106f082608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610b
ef
565b6106fb57600061073f565b61073f82608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610
c42
565b5b600160a060020a038716600090815260026020526040
90
205484018
1
9003
955090
505b50505050919050565b60008183106107
7b
57816107
7d
565b825b90505b92915050565b60408051908101604052600381527f5354520000000000000000000000000000000000000000000000000000000000602082015281565b60008060006107
cb
33610b
ad
565b92506108
11
83608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610b
ef
565b151561081
9
57fe5b61085
d
83608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610
d38
565b60018501546002860154929450909250600160a060020a039081169133909116907f96c5271ec05cb2683bdc50cf109341f5a4e45b02907df1c23a8855bddbe030a190858560405180848152602001838152602001828152602001935050505060405180910390a36105f333610
e06
565b5b505050565b6005545b90565b60008
0821180156108f45750816108f1336105f8565b10155b15156108fc57fe5b600160a060020a033316600090815260026020526040902054829010156109805761092633610c00565b905061096c81608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610d38565b505081610978336105f8565b10
156109
80
57fe5b
5b
600160a060020a0333811660008181526002602052604080822080548
7
90039055928
6
168082529083902080548
6
019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908
5
905190815260200160405180910390a35b50505
05
65b60015433600160a060020a03908116911614610
a07
57600080fd5b600160a060020a03821660009081526002602052604081208054830190558054820190555b5050565b600080600080610
a3f
33610b
ad
565b600181015460028201546003830154600160a060020a03909216965094504203925090505b50909192565b600080600080610a
79
33610
c00
565b805460028201546003830154600160a060020a03909216965094504203925090505b50909192565b600160a060020a0333811660008181526002602090815260408083208390556003825280832083905560049091528120556001549091161415610b
aa
5760008054600160a060020a033316825260026020526040822055610
b04
90600590610e
b7
565b6005805460018101610
b16
8382610e
85
565b916000526020600020906004020160005b60806040519081016040908152600080835260208301819052908201819052606082015291905081518154600160a060020a031916600160a060020a03919091161781556020820151600182018054600160a060020a031916600160a060020a039290921691909117905560408201518160020155606082015181600301555050505b5b565b600160a060020a038116600090815260036020526040812054600580549091908110610b
d5
57fe5b906000526020600020906004020160005b5090505b919050565b60008160600151151590505b919050565b600160a060020a038116600090815260046020526040812054600580549091908110610b
d5
57fe5b906000526020600020906004020160005b5090505b919050565b6000806000806000610
c53
86610e
6e
565b9350610c
5f
8651610
c00
565b9250610c
a5
83608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610b
ef
565b610c
b0
576000610c
f4
565b610c
f4
83608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610
c42
565b5b9150600260008751600160a060020a0316
600160a060020a0316
81526020
0
190
8
15260
2
001600020549
050610d2c
848383016107
6c
565b94505b50505050919050565b600080600080600080610
d4a
87610
c42
565b9350866040015184811515610d
5b
57fe5b049250866040015183029150610d7
0
87610e
6e
565b905081600260008951600160a060020a0316600160a060020a031681526020019081526020016000206000828254039250508190555081600260008960200151600160a060020a031681526020810191909152604001600020805490910190558260608801818151019052504260608801511115610d
ea
57fe5b80821115610d
f4
57fe5b81828203955095505b50505050915091565b600160a060020a0381166000908152600360205260409020546005805482908110610
e2d
57fe5b906000526020600020906004020160005b508054600160a060020a0319908116825560018201805490911690556000600282018190556003909101555b5050565b60008160400151826060015142030290505b919050565b8154818355818115116105f3576004028160040283600052602060002091820191016105f39190610e
dc
565b5b505050565b5080546000825560040290600052602060002090810190610e
d8
9190610e
dc
565b5b50565b61046b91905b80821115610
f1b
578054600160a060020a0319908116825560018201805490911690556000600282018190556003820155600401610e
e2
565b5090565b905600a165627a7a72305820
945979f7af2eb1e6a377d69b2a7728655b89376d2d2d4cd29884bb7c5f68ca4a
0029
"
,
"
unlinked_binary
"
:
"
0x6060604052341561000f57600080fd5b6040516020806110
7f
833981016040528080519150505b60018054600160a060020a03191633600160a060020a03169081178255600090815260026020526040812083905582905560058054909181016100698382610103565b916000526020600020906004020160005b60806040519081016040908152600080835260208301819052908201819052606082015291905081518154600160a060020a031916600160a060020a03919091161781556020820151600182018054600160a060020a031916600160a060020a039290921691909117905560408201518160020155606082015181600301555050505b5061017b565b81548183558181151161012f5760040281600402836000526020600020918201910161012f9190610135565b5b505050565b61017891905b80821115610174578054600160a060020a031990811682556001820180549091169055600060028201819055600382015560040161013b565b5090565b90565b610
ef5
8061018a6000396000f300606060405236156100d85763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100dd57806318160ddd14610168578063313ce5671461018d5780635cc8ce33146101b657806364a80c0c146101db57806370a08231146101ff5780637ae2b5c71461023057806395d89b411461025b5780639dad9382146102e6578063a1365fda146102fb578063a9059cbb14610320578063e13e2ecf14610344578063e61b959e14610368578063e8f88890146103b1578063f408ebe9146103fa575b600080fd5b34156100e857600080fd5b6100f061040f565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561012d5780820151818401525b602001610114565b50505050905090810190601f16801561015a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561017357600080fd5b61017b610446565b60405190815260200160405180910390f35b341561019857600080fd5b6101a061044c565b60405160ff909116815260200160405180910390f35b34156101c157600080fd5b61017b610451565b60405190815260200160405180910390f35b34156101e657600080fd5b6101fd600160a060020a036004351660243561046e565b005b341561020a57600080fd5b61017b600160a060020a03600435166105f8565b60405190815260200160405180910390f35b341561023b57600080fd5b61017b6004356024356107
94
565b60405190815260200160405180910390f35b341561026657600080fd5b6100f06107
ae
565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561012d5780820151818401525b602001610114565b50505050905090810190601f16801561015a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156102f157600080fd5b6101fd6107
e5
565b005b341561030657600080fd5b61017b6108
fc
565b60405190815260200160405180910390f35b341561032b57600080fd5b6101fd600160a060020a0360043516602435610
903
565b005b341561034f57600080fd5b6101fd600160a060020a03600435166024356109
8d
565b005b341561037357600080fd5b61037b610
9d1
565b6040518084600160a060020a0316600160a060020a03168152602001838152602001828152602001935050505060405180910390f35b34156103bc57600080fd5b61037b610a
0b
565b6040518084600160a060020a0316600160a060020a03168152602001838152602001828152602001935050505060405180910390f35b341561040557600080fd5b6101fd610a
42
565b005b60408051908101604052600681527f53747265656d0000000000000000000000000000000000000000000000000000602082015281565b60005481565b600081565b600160a060020a0333166000908152600260205260409020545b90565b60006104bc61047c33610b
4e
565b608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610b
90
565b156104c357fe5b60006104ce336105f8565b10156104d657fe5b6001600580548060010182816104ec9190610e
2c
565b916000526020600020906004020160005b60806040519081016040908152600160a060020a03338116835289166020830152810187905242606082015291905081518154600160a060020a031916600160a060020a03919091161781556020820151600182018054600160a060020a031916600160a060020a0392909216919091179055604082015181600201556060820151600391820155600160a060020a03338116600081815260209384526040808220979096039687905591891680835260049093529084902085905593945092917f4baaa557c21346b70bdc9482890b5d7e315f6a2123611e74004857ebecde0686915085905190815260200160405180910390a35b505050565b600080600080600061060986610
ba1
565b935061064f84608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610b
90
565b61065a57600061069e565b61069e84608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610
be3
565b5b92506106aa86610b
4e
565b91506106f082608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610b
90
565b6106fb57600061073f565b61073f82608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610
be3
565b5b600160a060020a038716600090815260026020526040
81
2054
91925090
84018
2
9003
121561076a57fe5b600160a060020a038616600090815260026020526040902054830181900394
505b50505050919050565b60008183106107
a3
57816107
a5
565b825b90505b92915050565b60408051908101604052600381527f5354520000000000000000000000000000000000000000000000000000000000602082015281565b60008060006107
f3
33610b
4e
565b92506108
39
83608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610b
90
565b15156108
4
157fe5b6108
8
583608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610
cdf
565b60018501546002860154929450909250600160a060020a039081169133909116907f96c5271ec05cb2683bdc50cf109341f5a4e45b02907df1c23a8855bddbe030a190858560405180848152602001838152602001828152602001935050505060405180910390a36105f333610
dad
565b5b505050565b6005545b90565b60008
111801561091b575080610918336105f8565b10155b15
156109
23
57fe5b600160a060020a0333811660008181526002602052604080822080548
6
90039055928
5
168082529083902080548
5
019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908
4
905190815260200160405180910390a35b5050565b60015433600160a060020a03908116911614610
9a8
57600080fd5b600160a060020a03821660009081526002602052604081208054830190558054820190555b5050565b600080600080610
9e0
33610b
4e
565b600181015460028201546003830154600160a060020a03909216965094504203925090505b50909192565b600080600080610a
1a
33610
ba1
565b805460028201546003830154600160a060020a03909216965094504203925090505b50909192565b600160a060020a0333811660008181526002602090815260408083208390556003825280832083905560049091528120556001549091161415610b
4b
5760008054600160a060020a033316825260026020526040822055610
aa5
90600590610e
5e
565b6005805460018101610
ab7
8382610e
2c
565b916000526020600020906004020160005b60806040519081016040908152600080835260208301819052908201819052606082015291905081518154600160a060020a031916600160a060020a03919091161781556020820151600182018054600160a060020a031916600160a060020a039290921691909117905560408201518160020155606082015181600301555050505b5b565b600160a060020a038116600090815260036020526040812054600580549091908110610b
76
57fe5b906000526020600020906004020160005b5090505b919050565b60008160600151151590505b919050565b600160a060020a038116600090815260046020526040812054600580549091908110610b
76
57fe5b906000526020600020906004020160005b5090505b919050565b6000806000806000610
bf4
86610e
15
565b9350610c
00
8651610
ba1
565b9250610c
46
83608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610b
90
565b610c
51
576000610c
95
565b610c
95
83608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610
be3
565b5b9150600260008751600160a060020a031681526020
81019
190
9
15260
4
0016000
9081
20549
1508282011215610cc757fe5b610cd3
848383016107
94
565b94505b50505050919050565b600080600080600080610
cf1
87610
be3
565b9350866040015184811515610d
02
57fe5b049250866040015183029150610d
1
787610e
15
565b905081600260008951600160a060020a0316600160a060020a031681526020019081526020016000206000828254039250508190555081600260008960200151600160a060020a031681526020810191909152604001600020805490910190558260608801818151019052504260608801511115610d
91
57fe5b80821115610d
9b
57fe5b81828203955095505b50505050915091565b600160a060020a0381166000908152600360205260409020546005805482908110610
dd4
57fe5b906000526020600020906004020160005b508054600160a060020a0319908116825560018201805490911690556000600282018190556003909101555b5050565b60008160400151826060015142030290505b919050565b8154818355818115116105f3576004028160040283600052602060002091820191016105f39190610e
83
565b5b505050565b5080546000825560040290600052602060002090810190610e
7f
9190610e
83
565b5b50565b61046b91905b80821115610
ec2
578054600160a060020a0319908116825560018201805490911690556000600282018190556003820155600401610e
89
565b5090565b905600a165627a7a72305820
d00c5aac227632ff138d1a4fa835789fdf6e37adb194ce535e3394712417a679
0029
"
,
"
networks
"
:
{
"
1500075197859
"
:
{
"
events
"
:
{
...
...
@@ -982,10 +982,10 @@ const contract = {
}
},
"
links
"
:
{},
"
address
"
:
"
0x
58c5cd125283b58476af87fe8c53c11ba0f7a735
"
,
"
updated_at
"
:
1502
035108745
"
address
"
:
"
0x
c5dc2ba3aee4b8c2cdc659a27118a5c5317705dd
"
,
"
updated_at
"
:
1502
119211001
}
},
"
schema_version
"
:
"
0.0.5
"
,
"
updated_at
"
:
1502
035108745
"
updated_at
"
:
1502
119211001
}
\ No newline at end of file
frontend/js/test.js
View file @
5a6340b7
...
...
@@ -42,15 +42,16 @@ function initContract() {
})
}
const
nrTestAccounts
=
5
// for f it expects a function which takes an address as argument
function
exec
ForTestAccs
(
f
)
{
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
function
apply
ForTestAccs
(
f
)
{
for
(
let
i
=
0
;
i
<
nrTestAccounts
;
i
++
)
{
f
(
web3
.
eth
.
accounts
[
i
])
}
}
function
updateDetailTable
()
{
exec
ForTestAccs
(
(
addr
,
i
)
=>
{
apply
ForTestAccs
(
(
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
()
{
exec
ForTestAccs
(
addr
=>
{
streem
.
closeStream
({
from
:
addr
,
gas
:
200000
},
(
err
,
ret
)
=>
{
apply
ForTestAccs
(
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
frontend/test.html
View file @
5a6340b7
...
...
@@ -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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment