swarm: addressed PR comments

This commit is contained in:
Fabio Barone 2018-12-14 22:05:02 -05:00
parent c3dbf9b5e7
commit a4189b4ab3
2 changed files with 11 additions and 13 deletions

View file

@ -776,9 +776,9 @@ type StreamerPrices struct {
} }
//Price implements the accounting interface and returns the price for a specific message //Price implements the accounting interface and returns the price for a specific message
func (spo *StreamerPrices) Price(msg interface{}) *protocols.Price { func (sp *StreamerPrices) Price(msg interface{}) *protocols.Price {
typ := reflect.TypeOf(msg).Elem() t := reflect.TypeOf(msg).Elem()
return spo.priceMatrix[typ] return sp.priceMatrix[t]
} }
//createPriceOracle sets up a matrix which can be queried to get //createPriceOracle sets up a matrix which can be queried to get
@ -789,12 +789,12 @@ func (r *Registry) createPriceOracle() {
} }
po.priceMatrix = map[reflect.Type]*protocols.Price{ po.priceMatrix = map[reflect.Type]*protocols.Price{
reflect.TypeOf(ChunkDeliveryMsgRetrieval{}): { reflect.TypeOf(ChunkDeliveryMsgRetrieval{}): {
Value: uint64(100), Value: uint64(1), //arbitrary price for now
PerByte: true, PerByte: true,
Payer: protocols.Receiver, Payer: protocols.Receiver,
}, },
reflect.TypeOf(RetrieveRequestMsg{}): { reflect.TypeOf(RetrieveRequestMsg{}): {
Value: uint64(10), Value: uint64(1), //arbitrary price for now
PerByte: false, PerByte: false,
Payer: protocols.Sender, Payer: protocols.Sender,
}, },

View file

@ -149,7 +149,6 @@ func TestSwapNetworkSymmetricFileUpload(t *testing.T) {
for _, node := range sim.NodeIDs() { for _, node := range sim.NodeIDs() {
item, ok := sim.NodeItem(node, bucketKeySwarm) item, ok := sim.NodeItem(node, bucketKeySwarm)
if !ok { if !ok {
log.Error("No swarm")
return errors.New("No swarm") return errors.New("No swarm")
} }
swarm := item.(*Swarm) swarm := item.(*Swarm)
@ -200,7 +199,7 @@ func TestSwapNetworkSymmetricFileUpload(t *testing.T) {
//but in inverted signs //but in inverted signs
//iterate the map //iterate the map
success := true errorFound := false
for k, mapForK := range balancesMap { for k, mapForK := range balancesMap {
//iterate the submap //iterate the submap
for n, balanceKwithN := range mapForK { for n, balanceKwithN := range mapForK {
@ -211,11 +210,11 @@ func TestSwapNetworkSymmetricFileUpload(t *testing.T) {
//...check that they have the same balance in Abs terms and that it is not 0 //...check that they have the same balance in Abs terms and that it is not 0
if balanceKwithN+mapForSubK[k] != 0 && balanceKwithN != 0 { if balanceKwithN+mapForSubK[k] != 0 && balanceKwithN != 0 {
log.Error(fmt.Sprintf("Expected balances to be a+b = 0 AND balance(a) != 0, but they are not, balance k with n: %d, balance n with k: %d", balanceKwithN, mapForSubK[k])) log.Error(fmt.Sprintf("Expected balances to be a+b = 0 AND balance(a) != 0, but they are not, balance k with n: %d, balance n with k: %d", balanceKwithN, mapForSubK[k]))
success = false errorFound = true
} }
} }
} }
if !success { if errorFound {
t.Fatal("Expected balances to be symmetrical, but they were not") t.Fatal("Expected balances to be symmetrical, but they were not")
} }
log.Debug("test terminated") log.Debug("test terminated")
@ -325,7 +324,6 @@ func TestSwapNetworkAsymmetricFileUpload(t *testing.T) {
for _, node := range sim.NodeIDs() { for _, node := range sim.NodeIDs() {
item, ok := sim.NodeItem(node, bucketKeySwarm) item, ok := sim.NodeItem(node, bucketKeySwarm)
if !ok { if !ok {
log.Error("No swarm")
return errors.New("no swarm") return errors.New("no swarm")
} }
swarm := item.(*Swarm) swarm := item.(*Swarm)
@ -367,7 +365,7 @@ func TestSwapNetworkAsymmetricFileUpload(t *testing.T) {
Assuming that in this case, balances should be symmetric too I Assuming that in this case, balances should be symmetric too I
*/ */
success := true errorsFound := false
for k, mapForK := range balancesMap { for k, mapForK := range balancesMap {
for n, balanceKwithN := range mapForK { for n, balanceKwithN := range mapForK {
mapForSubK := balancesMap[n] mapForSubK := balancesMap[n]
@ -375,12 +373,12 @@ func TestSwapNetworkAsymmetricFileUpload(t *testing.T) {
log.Trace(fmt.Sprintf("balance of %s with %s: %d", n.TerminalString(), k.TerminalString(), mapForSubK[k])) log.Trace(fmt.Sprintf("balance of %s with %s: %d", n.TerminalString(), k.TerminalString(), mapForSubK[k]))
if balanceKwithN+mapForSubK[k] != 0 && balanceKwithN != 0 { if balanceKwithN+mapForSubK[k] != 0 && balanceKwithN != 0 {
log.Error(fmt.Sprintf("Expected balances to be a+b = 0 AND balance(a) != 0, but they are not, balance k with n: %d, balance n with k: %d", balanceKwithN, mapForSubK[k])) log.Error(fmt.Sprintf("Expected balances to be a+b = 0 AND balance(a) != 0, but they are not, balance k with n: %d, balance n with k: %d", balanceKwithN, mapForSubK[k]))
success = false errorsFound = true
} }
} }
} }
if !success { if errorsFound {
t.Fatal("Expected balances to be symmetrical, but they were not") t.Fatal("Expected balances to be symmetrical, but they were not")
} }
log.Debug("test terminated") log.Debug("test terminated")