@ -89,12 +89,12 @@ func TestFeedsHandler(t *testing.T) {
}
defer teardownTest ( )
// create a new resource
// create a new Feed
ctx , cancel := context . WithCancel ( context . Background ( ) )
defer cancel ( )
topic , _ := NewTopic ( "Mess with Swarm Feeds code and see what ghost catches you" , nil )
view := Feed {
feed := Feed {
Topic : topic ,
User : signer . Address ( ) ,
}
@ -107,7 +107,7 @@ func TestFeedsHandler(t *testing.T) {
"clyde" , // t=4285
}
request := NewFirstRequest ( view . Topic ) // this timestamps the update at t = 4200 (start time)
request := NewFirstRequest ( feed . Topic ) // this timestamps the update at t = 4200 (start time)
chunkAddress := make ( map [ string ] storage . Address )
data := [ ] byte ( updates [ 0 ] )
request . SetData ( data )
@ -205,38 +205,38 @@ func TestFeedsHandler(t *testing.T) {
t . Fatal ( err )
}
rsrc 2, err := feedsHandler2 . Lookup ( ctx , NewQueryLatest ( & request . Feed , lookup . NoClue ) )
update 2, err := feedsHandler2 . Lookup ( ctx , NewQueryLatest ( & request . Feed , lookup . NoClue ) )
if err != nil {
t . Fatal ( err )
}
// last update should be "clyde"
if ! bytes . Equal ( rsrc 2. data , [ ] byte ( updates [ len ( updates ) - 1 ] ) ) {
t . Fatalf ( "resourc e data was %v, expected %v" , string ( rsrc 2. data ) , updates [ len ( updates ) - 1 ] )
if ! bytes . Equal ( update 2. data , [ ] byte ( updates [ len ( updates ) - 1 ] ) ) {
t . Fatalf ( "feed updat e data was %v, expected %v" , string ( update 2. data ) , updates [ len ( updates ) - 1 ] )
}
if rsrc 2. Level != 22 {
t . Fatalf ( "resource epoch level was %d, expected 22" , rsrc 2 . Level )
if update 2. Level != 22 {
t . Fatalf ( "feed update epoch level was %d, expected 22" , update 2 . Level )
}
if rsrc 2. Base ( ) != 0 {
t . Fatalf ( "resource epoch base time was %d, expected 0" , rsrc 2 . Base ( ) )
if update 2. Base ( ) != 0 {
t . Fatalf ( "feed update epoch base time was %d, expected 0" , update 2 . Base ( ) )
}
log . Debug ( "Latest lookup" , "epoch base time" , rsrc 2. Base ( ) , "epoch level" , rsrc 2. Level , "data" , rsrc 2. data )
log . Debug ( "Latest lookup" , "epoch base time" , update 2. Base ( ) , "epoch level" , update 2. Level , "data" , update 2. data )
// specific point in time
rsrc , err := feedsHandler2 . Lookup ( ctx , NewQuery ( & request . Feed , 4284 , lookup . NoClue ) )
update , err := feedsHandler2 . Lookup ( ctx , NewQuery ( & request . Feed , 4284 , lookup . NoClue ) )
if err != nil {
t . Fatal ( err )
}
// check data
if ! bytes . Equal ( rsrc . data , [ ] byte ( updates [ 2 ] ) ) {
t . Fatalf ( "resourc e data (historical) was %v, expected %v" , string ( rsrc 2. data ) , updates [ 2 ] )
if ! bytes . Equal ( update . data , [ ] byte ( updates [ 2 ] ) ) {
t . Fatalf ( "feed updat e data (historical) was %v, expected %v" , string ( update 2. data ) , updates [ 2 ] )
}
log . Debug ( "Historical lookup" , "epoch base time" , rsrc 2. Base ( ) , "epoch level" , rsrc 2. Level , "data" , rsrc 2. data )
log . Debug ( "Historical lookup" , "epoch base time" , update 2. Base ( ) , "epoch level" , update 2. Level , "data" , update 2. data )
// beyond the first should yield an error
rsrc , err = feedsHandler2 . Lookup ( ctx , NewQuery ( & request . Feed , startTime . Time - 1 , lookup . NoClue ) )
update , err = feedsHandler2 . Lookup ( ctx , NewQuery ( & request . Feed , startTime . Time - 1 , lookup . NoClue ) )
if err == nil {
t . Fatalf ( "expected previous to fail, returned epoch %s data %v" , rsrc . Epoch . String ( ) , rsrc . data )
t . Fatalf ( "expected previous to fail, returned epoch %s data %v" , update . Epoch . String ( ) , update . data )
}
}
@ -266,11 +266,11 @@ func TestSparseUpdates(t *testing.T) {
defer teardownTest ( )
defer os . RemoveAll ( datadir )
// create a new resource
// create a new Feed
ctx , cancel := context . WithCancel ( context . Background ( ) )
defer cancel ( )
topic , _ := NewTopic ( "Very slow updates" , nil )
view := Feed {
feed := Feed {
Topic : topic ,
User : signer . Address ( ) ,
}
@ -280,7 +280,7 @@ func TestSparseUpdates(t *testing.T) {
var epoch lookup . Epoch
var lastUpdateTime uint64
for T := uint64 ( 0 ) ; T < today ; T += 5 * Year {
request := NewFirstRequest ( view . Topic )
request := NewFirstRequest ( feed . Topic )
request . Epoch = lookup . GetNextEpoch ( epoch , T )
request . data = generateData ( T ) // this generates some data that depends on T, so we can check later
request . Sign ( signer )
@ -295,14 +295,14 @@ func TestSparseUpdates(t *testing.T) {
lastUpdateTime = T
}
query := NewQuery ( & view , today , lookup . NoClue )
query := NewQuery ( & feed , today , lookup . NoClue )
_ , err = rh . Lookup ( ctx , query )
if err != nil {
t . Fatal ( err )
}
_ , content , err := rh . GetContent ( & view )
_ , content , err := rh . GetContent ( & feed )
if err != nil {
t . Fatal ( err )
}
@ -321,7 +321,7 @@ func TestSparseUpdates(t *testing.T) {
t . Fatal ( err )
}
_ , content , err = rh . GetContent ( & view )
_ , content , err = rh . GetContent ( & feed )
if err != nil {
t . Fatal ( err )
}
@ -348,7 +348,7 @@ func TestValidator(t *testing.T) {
}
defer teardownTest ( )
// create new resource
// create new Feed
topic , _ := NewTopic ( subtopicName , nil )
feed := Feed {
Topic : topic ,
@ -382,7 +382,7 @@ func TestValidator(t *testing.T) {
}
// tests that the content address validator correctly checks the data
// tests that resource update chunks are passed through content address validator
// tests that Feed update chunks are passed through content address validator
// there is some redundancy in this test as it also tests content addressed chunks,
// which should be evaluated as invalid chunks by this validator
func TestValidatorInStore ( t * testing . T ) {
@ -409,7 +409,7 @@ func TestValidatorInStore(t *testing.T) {
t . Fatal ( err )
}
// set up resource handler and add is as a validator to the localstore
// set up Swa rm Fe ed s handler and add is as a validator to the localstore
fhParams := & HandlerParams { }
fh := NewHandler ( fhParams )
store . Validators = append ( store . Validators , fh )
@ -425,7 +425,7 @@ func TestValidatorInStore(t *testing.T) {
User : signer . Address ( ) ,
}
// create a resource update chunk with correct publickey
// create a feed update chunk with correct publickey
id := ID {
Epoch : lookup . Epoch { Time : 42 ,
Level : 1 ,