Commit 45cd76b4 authored by didi's avatar didi
Browse files

fixed circularity check, added tests. refs #2

parent 0866c0a4
......@@ -163,7 +163,7 @@ contract Streem {
// naming: osb -> outgoingStreamBalance, isb -> incomingStreamBalance, sb -> static balance
uint256 osb = naiveStreamBalance(s);
if(equals(s, origin)) { // special case: break on circular dependency. TODO: proof correctness
if(equals(s, origin) && hops > 1) { // special case: break on circular dependency. TODO: proof correctness
return osb;
} else {
var inS = getInStreamOf(s.sender);
......
......@@ -317,7 +317,7 @@ const contract = {
"type": "event"
}
],
"unlinked_binary": "0x6060604052341561000f57600080fd5b604051602080611176833981016040528080519150505b60018054600160a060020a03191633600160a060020a03169081178255600090815260026020526040812083905582905560058054909181016100698382610103565b916000526020600020906004020160005b60806040519081016040908152600080835260208301819052908201819052606082015291905081518154600160a060020a031916600160a060020a03919091161781556020820151600182018054600160a060020a031916600160a060020a039290921691909117905560408201518160020155606082015181600301555050505b5061017b565b81548183558181151161012f5760040281600402836000526020600020918201910161012f9190610135565b5b505050565b61017891905b80821115610174578054600160a060020a031990811682556001820180549091169055600060028201819055600382015560040161013b565b5090565b90565b610fec8061018a6000396000f300606060405236156100d85763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100dd57806318160ddd14610168578063313ce5671461018d5780635cc8ce33146101b657806364a80c0c146101db57806370a08231146101ff5780637ae2b5c71461023057806395d89b411461025b5780639dad9382146102e6578063a1365fda146102fb578063a9059cbb14610320578063e13e2ecf14610344578063e61b959e14610368578063e8f88890146103b1578063f408ebe9146103fa575b600080fd5b34156100e857600080fd5b6100f061040f565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561012d5780820151818401525b602001610114565b50505050905090810190601f16801561015a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561017357600080fd5b61017b610446565b60405190815260200160405180910390f35b341561019857600080fd5b6101a061044c565b60405160ff909116815260200160405180910390f35b34156101c157600080fd5b61017b610451565b60405190815260200160405180910390f35b34156101e657600080fd5b6101fd600160a060020a036004351660243561046e565b005b341561020a57600080fd5b61017b600160a060020a03600435166105f8565b60405190815260200160405180910390f35b341561023b57600080fd5b61017b60043560243561081c565b60405190815260200160405180910390f35b341561026657600080fd5b6100f0610836565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561012d5780820151818401525b602001610114565b50505050905090810190601f16801561015a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156102f157600080fd5b6101fd61086d565b005b341561030657600080fd5b61017b610984565b60405190815260200160405180910390f35b341561032b57600080fd5b6101fd600160a060020a036004351660243561098b565b005b341561034f57600080fd5b6101fd600160a060020a0360043516602435610a15565b005b341561037357600080fd5b61037b610a59565b6040518084600160a060020a0316600160a060020a03168152602001838152602001828152602001935050505060405180910390f35b34156103bc57600080fd5b61037b610a93565b6040518084600160a060020a0316600160a060020a03168152602001838152602001828152602001935050505060405180910390f35b341561040557600080fd5b6101fd610aca565b005b60408051908101604052600681527f53747265656d0000000000000000000000000000000000000000000000000000602082015281565b60005481565b600081565b600160a060020a0333166000908152600260205260409020545b90565b60006104bc61047c33610bd6565b608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610c18565b156104c357fe5b60006104ce336105f8565b10156104d657fe5b6001600580548060010182816104ec9190610f23565b916000526020600020906004020160005b60806040519081016040908152600160a060020a03338116835289166020830152810187905242606082015291905081518154600160a060020a031916600160a060020a03919091161781556020820151600182018054600160a060020a031916600160a060020a0392909216919091179055604082015181600201556060820151600391820155600160a060020a03338116600081815260209384526040808220979096039687905591891680835260049093529084902085905593945092917f4baaa557c21346b70bdc9482890b5d7e315f6a2123611e74004857ebecde0686915085905190815260200160405180910390a35b505050565b600080600080600061060986610c29565b935061064f84608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610c18565b61065a5760006106e2565b6106e284608060405190810160409081528254600160a060020a039081168352600184015416602083015260028301548183015260039092015460608201529086906080905190810160409081528254600160a060020a0390811683526001808501549091166020840152600284015491830191909152600390920154606082015290610c6b565b5b92506106ee86610bd6565b915061073482608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610c18565b61073f5760006107c7565b6107c782608060405190810160409081528254600160a060020a039081168352600184015416602083015260028301548183015260039092015460608201529084906080905190810160409081528254600160a060020a0390811683526001808501549091166020840152600284015491830191909152600390920154606082015290610c6b565b5b600160a060020a03871660009081526002602052604081205491925090840182900312156107f257fe5b600160a060020a038616600090815260026020526040902054830181900394505b50505050919050565b600081831061082b578161082d565b825b90505b92915050565b60408051908101604052600381527f5354520000000000000000000000000000000000000000000000000000000000602082015281565b600080600061087b33610bd6565b92506108c183608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610c18565b15156108c957fe5b61090d83608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610d8c565b60018501546002860154929450909250600160a060020a039081169133909116907f96c5271ec05cb2683bdc50cf109341f5a4e45b02907df1c23a8855bddbe030a190858560405180848152602001838152602001828152602001935050505060405180910390a36105f333610e5d565b5b505050565b6005545b90565b6000811180156109a35750806109a0336105f8565b10155b15156109ab57fe5b600160a060020a033381166000818152600260205260408082208054869003905592851680825290839020805485019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9084905190815260200160405180910390a35b5050565b60015433600160a060020a03908116911614610a3057600080fd5b600160a060020a03821660009081526002602052604081208054830190558054820190555b5050565b600080600080610a6833610bd6565b600181015460028201546003830154600160a060020a03909216965094504203925090505b50909192565b600080600080610aa233610c29565b805460028201546003830154600160a060020a03909216965094504203925090505b50909192565b600160a060020a0333811660008181526002602090815260408083208390556003825280832083905560049091528120556001549091161415610bd35760008054600160a060020a033316825260026020526040822055610b2d90600590610f55565b6005805460018101610b3f8382610f23565b916000526020600020906004020160005b60806040519081016040908152600080835260208301819052908201819052606082015291905081518154600160a060020a031916600160a060020a03919091161781556020820151600182018054600160a060020a031916600160a060020a039290921691909117905560408201518160020155606082015181600301555050505b5b565b600160a060020a038116600090815260036020526040812054600580549091908110610bfe57fe5b906000526020600020906004020160005b5090505b919050565b60008160600151151590505b919050565b600160a060020a038116600090815260046020526040812054600580549091908110610bfe57fe5b906000526020600020906004020160005b5090505b919050565b6000806000806000610c7c88610ec5565b9350610c888888610edc565b15610c9557839450610d80565b610c9f8851610c29565b9250610ce583608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610c18565b610cf0576000610d3f565b610d3f83608060405190810160409081528254600160a060020a039081168352600180850154909116602084015260028401549183019190915260039092015460608201529089908901610c6b565b5b9150600260008951600160a060020a03168152602081019190915260400160009081205491508282011215610d7157fe5b610d7d8483830161081c565b94505b5b505050509392505050565b600080600080600080610da187886001610c6b565b9350866040015184811515610db257fe5b049250866040015183029150610dc787610ec5565b905081600260008951600160a060020a0316600160a060020a031681526020019081526020016000206000828254039250508190555081600260008960200151600160a060020a031681526020810191909152604001600020805490910190558260608801818151019052504260608801511115610e4157fe5b80821115610e4b57fe5b81828203955095505b50505050915091565b600160a060020a0381166000908152600360205260409020546005805482908110610e8457fe5b906000526020600020906004020160005b508054600160a060020a0319908116825560018201805490911690556000600282018190556003909101555b5050565b60008160400151826060015142030290505b919050565b60008151600160a060020a03168351600160a060020a031614801561082d57508160200151600160a060020a03168360200151600160a060020a0316145b90505b92915050565b8154818355818115116105f3576004028160040283600052602060002091820191016105f39190610f7a565b5b505050565b5080546000825560040290600052602060002090810190610f769190610f7a565b5b50565b61046b91905b80821115610fb9578054600160a060020a0319908116825560018201805490911690556000600282018190556003820155600401610f80565b5090565b905600a165627a7a72305820c51cb66e2d5a2a7215690fe6faed582be0203adebe118b7319e3572f864587660029",
"unlinked_binary": "0x6060604052341561000f57600080fd5b604051602080611182833981016040528080519150505b60018054600160a060020a03191633600160a060020a03169081178255600090815260026020526040812083905582905560058054909181016100698382610103565b916000526020600020906004020160005b60806040519081016040908152600080835260208301819052908201819052606082015291905081518154600160a060020a031916600160a060020a03919091161781556020820151600182018054600160a060020a031916600160a060020a039290921691909117905560408201518160020155606082015181600301555050505b5061017b565b81548183558181151161012f5760040281600402836000526020600020918201910161012f9190610135565b5b505050565b61017891905b80821115610174578054600160a060020a031990811682556001820180549091169055600060028201819055600382015560040161013b565b5090565b90565b610ff88061018a6000396000f300606060405236156100d85763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100dd57806318160ddd14610168578063313ce5671461018d5780635cc8ce33146101b657806364a80c0c146101db57806370a08231146101ff5780637ae2b5c71461023057806395d89b411461025b5780639dad9382146102e6578063a1365fda146102fb578063a9059cbb14610320578063e13e2ecf14610344578063e61b959e14610368578063e8f88890146103b1578063f408ebe9146103fa575b600080fd5b34156100e857600080fd5b6100f061040f565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561012d5780820151818401525b602001610114565b50505050905090810190601f16801561015a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561017357600080fd5b61017b610446565b60405190815260200160405180910390f35b341561019857600080fd5b6101a061044c565b60405160ff909116815260200160405180910390f35b34156101c157600080fd5b61017b610451565b60405190815260200160405180910390f35b34156101e657600080fd5b6101fd600160a060020a036004351660243561046e565b005b341561020a57600080fd5b61017b600160a060020a03600435166105f8565b60405190815260200160405180910390f35b341561023b57600080fd5b61017b60043560243561081c565b60405190815260200160405180910390f35b341561026657600080fd5b6100f0610836565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561012d5780820151818401525b602001610114565b50505050905090810190601f16801561015a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156102f157600080fd5b6101fd61086d565b005b341561030657600080fd5b61017b610984565b60405190815260200160405180910390f35b341561032b57600080fd5b6101fd600160a060020a036004351660243561098b565b005b341561034f57600080fd5b6101fd600160a060020a0360043516602435610a15565b005b341561037357600080fd5b61037b610a59565b6040518084600160a060020a0316600160a060020a03168152602001838152602001828152602001935050505060405180910390f35b34156103bc57600080fd5b61037b610a93565b6040518084600160a060020a0316600160a060020a03168152602001838152602001828152602001935050505060405180910390f35b341561040557600080fd5b6101fd610aca565b005b60408051908101604052600681527f53747265656d0000000000000000000000000000000000000000000000000000602082015281565b60005481565b600081565b600160a060020a0333166000908152600260205260409020545b90565b60006104bc61047c33610bd6565b608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610c18565b156104c357fe5b60006104ce336105f8565b10156104d657fe5b6001600580548060010182816104ec9190610f2f565b916000526020600020906004020160005b60806040519081016040908152600160a060020a03338116835289166020830152810187905242606082015291905081518154600160a060020a031916600160a060020a03919091161781556020820151600182018054600160a060020a031916600160a060020a0392909216919091179055604082015181600201556060820151600391820155600160a060020a03338116600081815260209384526040808220979096039687905591891680835260049093529084902085905593945092917f4baaa557c21346b70bdc9482890b5d7e315f6a2123611e74004857ebecde0686915085905190815260200160405180910390a35b505050565b600080600080600061060986610c29565b935061064f84608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610c18565b61065a5760006106e2565b6106e284608060405190810160409081528254600160a060020a039081168352600184015416602083015260028301548183015260039092015460608201529086906080905190810160409081528254600160a060020a0390811683526001808501549091166020840152600284015491830191909152600390920154606082015290610c6b565b5b92506106ee86610bd6565b915061073482608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610c18565b61073f5760006107c7565b6107c782608060405190810160409081528254600160a060020a039081168352600184015416602083015260028301548183015260039092015460608201529084906080905190810160409081528254600160a060020a0390811683526001808501549091166020840152600284015491830191909152600390920154606082015290610c6b565b5b600160a060020a03871660009081526002602052604081205491925090840182900312156107f257fe5b600160a060020a038616600090815260026020526040902054830181900394505b50505050919050565b600081831061082b578161082d565b825b90505b92915050565b60408051908101604052600381527f5354520000000000000000000000000000000000000000000000000000000000602082015281565b600080600061087b33610bd6565b92506108c183608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610c18565b15156108c957fe5b61090d83608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610d98565b60018501546002860154929450909250600160a060020a039081169133909116907f96c5271ec05cb2683bdc50cf109341f5a4e45b02907df1c23a8855bddbe030a190858560405180848152602001838152602001828152602001935050505060405180910390a36105f333610e69565b5b505050565b6005545b90565b6000811180156109a35750806109a0336105f8565b10155b15156109ab57fe5b600160a060020a033381166000818152600260205260408082208054869003905592851680825290839020805485019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9084905190815260200160405180910390a35b5050565b60015433600160a060020a03908116911614610a3057600080fd5b600160a060020a03821660009081526002602052604081208054830190558054820190555b5050565b600080600080610a6833610bd6565b600181015460028201546003830154600160a060020a03909216965094504203925090505b50909192565b600080600080610aa233610c29565b805460028201546003830154600160a060020a03909216965094504203925090505b50909192565b600160a060020a0333811660008181526002602090815260408083208390556003825280832083905560049091528120556001549091161415610bd35760008054600160a060020a033316825260026020526040822055610b2d90600590610f61565b6005805460018101610b3f8382610f2f565b916000526020600020906004020160005b60806040519081016040908152600080835260208301819052908201819052606082015291905081518154600160a060020a031916600160a060020a03919091161781556020820151600182018054600160a060020a031916600160a060020a039290921691909117905560408201518160020155606082015181600301555050505b5b565b600160a060020a038116600090815260036020526040812054600580549091908110610bfe57fe5b906000526020600020906004020160005b5090505b919050565b60008160600151151590505b919050565b600160a060020a038116600090815260046020526040812054600580549091908110610bfe57fe5b906000526020600020906004020160005b5090505b919050565b6000806000806000610c7c88610ed1565b9350610c888888610ee8565b8015610c945750600186115b15610ca157839450610d8c565b610cab8851610c29565b9250610cf183608060405190810160409081528254600160a060020a03908116835260018401541660208301526002830154908201526003909101546060820152610c18565b610cfc576000610d4b565b610d4b83608060405190810160409081528254600160a060020a039081168352600180850154909116602084015260028401549183019190915260039092015460608201529089908901610c6b565b5b9150600260008951600160a060020a03168152602081019190915260400160009081205491508282011215610d7d57fe5b610d898483830161081c565b94505b5b505050509392505050565b600080600080600080610dad87886001610c6b565b9350866040015184811515610dbe57fe5b049250866040015183029150610dd387610ed1565b905081600260008951600160a060020a0316600160a060020a031681526020019081526020016000206000828254039250508190555081600260008960200151600160a060020a031681526020810191909152604001600020805490910190558260608801818151019052504260608801511115610e4d57fe5b80821115610e5757fe5b81828203955095505b50505050915091565b600160a060020a0381166000908152600360205260409020546005805482908110610e9057fe5b906000526020600020906004020160005b508054600160a060020a0319908116825560018201805490911690556000600282018190556003909101555b5050565b60008160400151826060015142030290505b919050565b60008151600160a060020a03168351600160a060020a031614801561082d57508160200151600160a060020a03168360200151600160a060020a0316145b90505b92915050565b8154818355818115116105f3576004028160040283600052602060002091820191016105f39190610f86565b5b505050565b5080546000825560040290600052602060002090810190610f829190610f86565b5b50565b61046b91905b80821115610fc5578054600160a060020a0319908116825560018201805490911690556000600282018190556003820155600401610f8c565b5090565b905600a165627a7a723058201701b6f1ba321331904375c9b7854d54f3bac56fa58c9d0fa519fa96f9008a1f0029",
"networks": {
"1500075197859": {
"events": {
......@@ -982,10 +982,10 @@ const contract = {
}
},
"links": {},
"address": "0xaa6857c10e5d6acc37e2e7b0efc2749dfb213077",
"updated_at": 1502127244263
"address": "0x9e655462bc832ba58f92031ee2e6cf354caa1571",
"updated_at": 1502180973953
}
},
"schema_version": "0.0.5",
"updated_at": 1502127244263
"updated_at": 1502180973953
}
\ No newline at end of file
......@@ -40,6 +40,11 @@ function initContract() {
onNextBlock(hash)
}
})
streem.allEvents({}, (err, ret) => {
console.log(`event ${JSON.stringify(ret.args)}`)
})
}
const nrTestAccounts = 5
......@@ -229,6 +234,14 @@ function test3b() {
streem.openStream(web3.eth.accounts[0], 1, {from: web3.eth.accounts[1], gas: 200000})
}
function test3c() {
console.log('open stream1: speed 2 from addr1 to addr2')
streem.openStream(web3.eth.accounts[2], 2, {from: web3.eth.accounts[1], gas: 200000})
console.log('open stream2: speed 1 from addr2 to addr1')
streem.openStream(web3.eth.accounts[1], 1, {from: web3.eth.accounts[2], 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})
......@@ -236,6 +249,17 @@ function test4() {
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})
}
function test4a() {
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})
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
......@@ -41,7 +41,9 @@ Size of streams array: <span id="nrstreams">-</span><br>
<button id="test3">Test3: open A->B (1), open B->A (1)</button><br>
<button id="test3a">Test3a: open A->B (1), open B->A (2)</button><br>
<button id="test3b">Test3b: open A->B (2), open B->A (1)</button><br>
<button id="test3c">Test3c: open B->C (2), open C->B (1)</button><br>
<button id="test4">Test4: open A->B (1), open B->C (1), open C->A (1)</button><br>
<button id="test4a">Test4a: open A->B (1), open B->C (2), 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