mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
swarm/storage: Replace global test blockcount with fakebackend ffwd
This commit is contained in:
parent
91cfddd375
commit
9f93345d4f
1 changed files with 21 additions and 10 deletions
|
|
@ -129,7 +129,10 @@ func TestResourceReverseLookup(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rh, _, err, teardownTest := setupTest(privkey, nil, zeroAddr)
|
backend := &fakeBackend{
|
||||||
|
blocknumber: 4200,
|
||||||
|
}
|
||||||
|
rh, _, err, teardownTest := setupTest(privkey, backend, zeroAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
teardownTest(t, err)
|
teardownTest(t, err)
|
||||||
}
|
}
|
||||||
|
|
@ -143,7 +146,7 @@ func TestResourceReverseLookup(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// update data
|
// update data
|
||||||
blockCount += resourcefrequency + 1
|
fwdBlocks(int(resourcefrequency+1), backend)
|
||||||
data := []byte("foo")
|
data := []byte("foo")
|
||||||
resourcekey, err := rh.Update(resourcename, data)
|
resourcekey, err := rh.Update(resourcename, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -187,7 +190,10 @@ func TestResourceHandler(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rh, datadir, err, teardownTest := setupTest(privkey, nil, zeroAddr)
|
backend := &fakeBackend{
|
||||||
|
blocknumber: 4200,
|
||||||
|
}
|
||||||
|
rh, datadir, err, teardownTest := setupTest(privkey, backend, zeroAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
teardownTest(t, err)
|
teardownTest(t, err)
|
||||||
}
|
}
|
||||||
|
|
@ -205,8 +211,8 @@ func TestResourceHandler(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check that the new resource is stored correctly
|
// check that the new resource is stored correctly
|
||||||
namehash := ens.EnsNode(resourcevalidname)
|
|
||||||
rawrh := rh.(*RawResourceHandler)
|
rawrh := rh.(*RawResourceHandler)
|
||||||
|
namehash := rawrh.nameHashFunc(resourcevalidname)
|
||||||
chunk, err := rawrh.ChunkStore.(*resourceChunkStore).localStore.(*LocalStore).memStore.Get(Key(namehash[:]))
|
chunk, err := rawrh.ChunkStore.(*resourceChunkStore).localStore.(*LocalStore).memStore.Get(Key(namehash[:]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
teardownTest(t, err)
|
teardownTest(t, err)
|
||||||
|
|
@ -215,8 +221,8 @@ func TestResourceHandler(t *testing.T) {
|
||||||
}
|
}
|
||||||
startblocknumber := binary.LittleEndian.Uint64(chunk.SData[8:16])
|
startblocknumber := binary.LittleEndian.Uint64(chunk.SData[8:16])
|
||||||
chunkfrequency := binary.LittleEndian.Uint64(chunk.SData[16:])
|
chunkfrequency := binary.LittleEndian.Uint64(chunk.SData[16:])
|
||||||
if startblocknumber != blockCount {
|
if startblocknumber != backend.blocknumber {
|
||||||
teardownTest(t, fmt.Errorf("stored block number %d does not match provided block number %d", startblocknumber, blockCount))
|
teardownTest(t, fmt.Errorf("stored block number %d does not match provided block number %d", startblocknumber, backend.blocknumber))
|
||||||
}
|
}
|
||||||
if chunkfrequency != resourcefrequency {
|
if chunkfrequency != resourcefrequency {
|
||||||
teardownTest(t, fmt.Errorf("stored frequency %d does not match provided frequency %d", chunkfrequency, resourcefrequency))
|
teardownTest(t, fmt.Errorf("stored frequency %d does not match provided frequency %d", chunkfrequency, resourcefrequency))
|
||||||
|
|
@ -224,28 +230,32 @@ func TestResourceHandler(t *testing.T) {
|
||||||
|
|
||||||
// update halfway to first period
|
// update halfway to first period
|
||||||
resourcekey := make(map[string]Key)
|
resourcekey := make(map[string]Key)
|
||||||
blockCount = startblocknumber + (resourcefrequency / 2)
|
//blockCount = startblocknumber + (resourcefrequency / 2)
|
||||||
|
fwdBlocks(int(resourcefrequency/2), backend)
|
||||||
resourcekey["blinky"], err = rh.Update(resourcename, []byte("blinky"))
|
resourcekey["blinky"], err = rh.Update(resourcename, []byte("blinky"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
teardownTest(t, err)
|
teardownTest(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// update on first period
|
// update on first period
|
||||||
blockCount = startblocknumber + resourcefrequency
|
//blockCount = startblocknumber + resourcefrequency
|
||||||
|
fwdBlocks(int(resourcefrequency/2), backend)
|
||||||
resourcekey["pinky"], err = rh.Update(resourcename, []byte("pinky"))
|
resourcekey["pinky"], err = rh.Update(resourcename, []byte("pinky"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
teardownTest(t, err)
|
teardownTest(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// update on second period
|
// update on second period
|
||||||
blockCount = startblocknumber + (resourcefrequency * 2)
|
//blockCount = startblocknumber + (resourcefrequency * 2)
|
||||||
|
fwdBlocks(int(resourcefrequency), backend)
|
||||||
resourcekey["inky"], err = rh.Update(resourcename, []byte("inky"))
|
resourcekey["inky"], err = rh.Update(resourcename, []byte("inky"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
teardownTest(t, err)
|
teardownTest(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// update just after second period
|
// update just after second period
|
||||||
blockCount = startblocknumber + (resourcefrequency * 2) + 1
|
//blockCount = startblocknumber + (resourcefrequency * 2) + 1
|
||||||
|
fwdBlocks(1, backend)
|
||||||
resourcekey["clyde"], err = rh.Update(resourcename, []byte("clyde"))
|
resourcekey["clyde"], err = rh.Update(resourcename, []byte("clyde"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
teardownTest(t, err)
|
teardownTest(t, err)
|
||||||
|
|
@ -256,6 +266,7 @@ func TestResourceHandler(t *testing.T) {
|
||||||
// check we can retrieve the updates after close
|
// check we can retrieve the updates after close
|
||||||
// it will match on second iteration startblocknumber + (resourcefrequency * 3)
|
// it will match on second iteration startblocknumber + (resourcefrequency * 3)
|
||||||
blockCount = startblocknumber + (resourcefrequency * 4)
|
blockCount = startblocknumber + (resourcefrequency * 4)
|
||||||
|
fwdBlocks(int(resourcefrequency*2)-1, backend)
|
||||||
|
|
||||||
rh2, err := NewRawResourceHandler(privkey, datadir, &testCloudStore{}, rawrh.rpcClient, nil)
|
rh2, err := NewRawResourceHandler(privkey, datadir, &testCloudStore{}, rawrh.rpcClient, nil)
|
||||||
_, err = rh2.LookupLatest(resourcename, true)
|
_, err = rh2.LookupLatest(resourcename, true)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue