[WIP] Add a service to fill indexing gap for watched addresses #135
10
cmd/serve.go
10
cmd/serve.go
@ -30,7 +30,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/statediff"
|
||||
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
|
||||
"github.com/mailgun/groupcache/v2"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
@ -305,7 +304,6 @@ func startStateTrieValidator(config *s.Config, server s.Server) {
|
||||
|
||||
type WatchedAddress struct {
|
||||
Address string `db:"address"`
|
||||
Kind int `db:"kind"`
|
||||
CreatedAt uint64 `db:"created_at"`
|
||||
WatchedAt uint64 `db:"watched_at"`
|
||||
LastFilledAt uint64 `db:"last_filled_at"`
|
||||
@ -343,15 +341,7 @@ func startWatchedAddressGapFiller(config *s.Config) {
|
||||
fillAddresses := []interface{}{}
|
||||
for _, fillWatchedAddress := range fillWatchedAddresses {
|
||||
if blockNumber >= fillWatchedAddress.startBlock && blockNumber <= fillWatchedAddress.endBlock {
|
||||
switch fillWatchedAddress.Kind {
|
||||
case sdtypes.WatchedAddress.Int():
|
||||
params.WatchedAddresses = append(params.WatchedAddresses, common.HexToAddress(fillWatchedAddress.Address))
|
||||
case sdtypes.WatchedStorageSlot.Int():
|
||||
params.WatchedStorageSlots = append(params.WatchedStorageSlots, common.HexToHash(fillWatchedAddress.Address))
|
||||
default:
|
||||
log.Fatalf("Unexpected kind %d:", fillWatchedAddress.Kind)
|
||||
}
|
||||
|
||||
fillAddresses = append(fillAddresses, fillWatchedAddress.Address)
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,10 @@ type StorageKey struct {
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
type CountIncremented struct {
|
||||
BlockNumber int64 `json:"blockNumber"`
|
||||
}
|
||||
|
||||
const srvUrl = "http://localhost:3000"
|
||||
|
||||
func DeployContract() (*ContractDeployed, error) {
|
||||
@ -105,22 +109,21 @@ func DeploySLVContract() (*ContractDeployed, error) {
|
||||
return &contract, nil
|
||||
}
|
||||
|
||||
func IncrementCountA(addr string) error {
|
||||
_, err := http.Get(fmt.Sprintf("%s/v1/incrementCountA?addr=%s", srvUrl, addr))
|
||||
func IncrementCount(addr string, count string) (*CountIncremented, error) {
|
||||
res, err := http.Get(fmt.Sprintf("%s/v1/incrementCount%s?addr=%s", srvUrl, count, addr))
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
var blockNumber CountIncremented
|
||||
|
||||
func IncrementCountB(addr string) error {
|
||||
_, err := http.Get(fmt.Sprintf("%s/v1/incrementCountB?addr=%s", srvUrl, addr))
|
||||
decoder := json.NewDecoder(res.Body)
|
||||
err = decoder.Decode(&blockNumber)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nil
|
||||
return &blockNumber, nil
|
||||
}
|
||||
|
||||
func GetStorageSlotKey(contract string, label string) (*StorageKey, error) {
|
||||
@ -146,13 +149,7 @@ func ClearWatchedAddresses(gethRPCClient *rpc.Client) error {
|
||||
args := []sdtypes.WatchAddressArg{}
|
||||
|
||||
// Clear watched addresses
|
||||
gethErr := gethRPCClient.Call(nil, gethMethod, statediff.ClearAddresses, args)
|
||||
if gethErr != nil {
|
||||
return gethErr
|
||||
}
|
||||
|
||||
// Clear watched storage slots
|
||||
gethErr = gethRPCClient.Call(nil, gethMethod, statediff.ClearStorageSlots, args)
|
||||
gethErr := gethRPCClient.Call(nil, gethMethod, statediff.Clear, args)
|
||||
if gethErr != nil {
|
||||
return gethErr
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/statediff"
|
||||
@ -45,16 +44,31 @@ var _ = Describe("WatchAddress integration test", func() {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
|
||||
txErr error
|
||||
contractErr error
|
||||
incErr error
|
||||
|
||||
contract1 *integration.ContractDeployed
|
||||
contract2 *integration.ContractDeployed
|
||||
contract3 *integration.ContractDeployed
|
||||
|
||||
countAIndex string
|
||||
countBIndex string
|
||||
countAStorageHash common.Hash
|
||||
countBStorageHash common.Hash
|
||||
|
||||
prevBalance1 *big.Int
|
||||
prevBalance2 *big.Int
|
||||
prevBalance3 *big.Int
|
||||
|
||||
actualBalance1 *big.Int
|
||||
actualBalance2 *big.Int
|
||||
actualBalance3 *big.Int
|
||||
|
||||
prevCountA1 *big.Int
|
||||
prevCountA2 *big.Int
|
||||
prevCountA3 *big.Int
|
||||
|
||||
actualCountA1 *big.Int
|
||||
actualCountA2 *big.Int
|
||||
actualCountA3 *big.Int
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
@ -74,63 +88,67 @@ var _ = Describe("WatchAddress integration test", func() {
|
||||
contract3, contractErr = integration.DeploySLVContract()
|
||||
Expect(contractErr).ToNot(HaveOccurred())
|
||||
|
||||
// Get storage slot keys
|
||||
// Get the storage slot key
|
||||
storageSlotAKey, err := integration.GetStorageSlotKey("SLVToken", "countA")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countAIndex = storageSlotAKey.Key
|
||||
countAStorageHash = crypto.Keccak256Hash(common.HexToHash(countAIndex).Bytes())
|
||||
|
||||
storageSlotBKey, err := integration.GetStorageSlotKey("SLVToken", "countB")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countBIndex = storageSlotBKey.Key
|
||||
countBStorageHash = crypto.Keccak256Hash(common.HexToHash(countBIndex).Bytes())
|
||||
})
|
||||
|
||||
defer It("test cleanup", func() {
|
||||
// Clear out watched addresses | storage slots
|
||||
err := integration.ClearWatchedAddresses(gethRPCClient)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
Describe("watched addresses", func() {
|
||||
var (
|
||||
txErr error
|
||||
|
||||
prevBalance1 *big.Int
|
||||
prevBalance2 *big.Int
|
||||
prevBalance3 *big.Int
|
||||
|
||||
actualBalance1 *big.Int
|
||||
actualBalance2 *big.Int
|
||||
actualBalance3 *big.Int
|
||||
)
|
||||
|
||||
It("watched addresses test init", func() {
|
||||
// Clear out watched addresses | storage slots
|
||||
err := integration.ClearWatchedAddresses(gethRPCClient)
|
||||
// Clear out watched addresses
|
||||
err = integration.ClearWatchedAddresses(gethRPCClient)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// Get initial balances for all the contracts
|
||||
// Contract 1
|
||||
actualBalance1 = big.NewInt(0)
|
||||
prevBalance1 = big.NewInt(0)
|
||||
initBalance1, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract1.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(initBalance1.String()).To(Equal(actualBalance1.String()))
|
||||
prevBalance1 = big.NewInt(0)
|
||||
|
||||
// Contract 2
|
||||
actualBalance2 = big.NewInt(0)
|
||||
prevBalance2 = big.NewInt(0)
|
||||
initBalance2, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract2.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(initBalance2.String()).To(Equal(actualBalance2.String()))
|
||||
prevBalance2 = big.NewInt(0)
|
||||
|
||||
// Contract 3
|
||||
actualBalance3 = big.NewInt(0)
|
||||
prevBalance3 = big.NewInt(0)
|
||||
initBalance3, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract3.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(initBalance3.String()).To(Equal(actualBalance3.String()))
|
||||
prevBalance3 = big.NewInt(0)
|
||||
|
||||
// Get initial storage values for the contracts
|
||||
// Contract 1, countA
|
||||
actualCountA1 = big.NewInt(0)
|
||||
ipldCountA1Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
ipldCountA1 := new(big.Int).SetBytes(ipldCountA1Storage)
|
||||
Expect(ipldCountA1.String()).To(Equal(actualCountA1.String()))
|
||||
prevCountA1 = big.NewInt(0)
|
||||
|
||||
// Contract 2, countA
|
||||
actualCountA2 = big.NewInt(0)
|
||||
ipldCountA2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
ipldCountA2 := new(big.Int).SetBytes(ipldCountA2Storage)
|
||||
Expect(ipldCountA2.String()).To(Equal(actualCountA2.String()))
|
||||
prevCountA2 = big.NewInt(0)
|
||||
|
||||
// Contract 3, countA
|
||||
actualCountA3 = big.NewInt(0)
|
||||
ipldCountA3Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
ipldCountA3 := new(big.Int).SetBytes(ipldCountA3Storage)
|
||||
Expect(ipldCountA3.String()).To(Equal(actualCountA2.String()))
|
||||
prevCountA3 = big.NewInt(0)
|
||||
})
|
||||
|
||||
defer It("test cleanup", func() {
|
||||
// Clear out watched addresses
|
||||
err := integration.ClearWatchedAddresses(gethRPCClient)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
Context("no contracts being watched", func() {
|
||||
@ -169,12 +187,49 @@ var _ = Describe("WatchAddress integration test", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance3AfterTransfer.String()).To(Equal(actualBalance3.String()))
|
||||
prevBalance3.Set(actualBalance3)
|
||||
|
||||
// Increment counts
|
||||
// Contract 1, countA
|
||||
_, incErr = integration.IncrementCount(contract1.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA1.Add(actualCountA1, big.NewInt(1))
|
||||
|
||||
countA1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1AfterIncrement := new(big.Int).SetBytes(countA1AfterIncrementStorage)
|
||||
Expect(countA1AfterIncrement.String()).To(Equal(actualCountA1.String()))
|
||||
prevCountA1.Set(actualCountA1)
|
||||
|
||||
// Contract 2, countA
|
||||
_, incErr = integration.IncrementCount(contract2.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA2.Add(actualCountA2, big.NewInt(1))
|
||||
|
||||
countA2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2AfterIncrement := new(big.Int).SetBytes(countA2AfterIncrementStorage)
|
||||
Expect(countA2AfterIncrement.String()).To(Equal(actualCountA2.String()))
|
||||
prevCountA2.Set(actualCountA2)
|
||||
|
||||
// Contract 3, countA
|
||||
_, incErr = integration.IncrementCount(contract3.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA3.Add(actualCountA3, big.NewInt(1))
|
||||
|
||||
countA3AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA3AfterIncrement := new(big.Int).SetBytes(countA3AfterIncrementStorage)
|
||||
Expect(countA3AfterIncrement.String()).To(Equal(actualCountA3.String()))
|
||||
prevCountA3.Set(actualCountA3)
|
||||
})
|
||||
})
|
||||
|
||||
Context("one contract being watched", func() {
|
||||
It("indexes state only for the watched contract", func() {
|
||||
operation := statediff.AddAddresses
|
||||
operation := statediff.Add
|
||||
args := []sdtypes.WatchAddressArg{
|
||||
{
|
||||
Address: contract1.Address,
|
||||
@ -216,12 +271,47 @@ var _ = Describe("WatchAddress integration test", func() {
|
||||
balance3AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract3.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance3AfterTransfer.String()).To(Equal(prevBalance3.String()))
|
||||
|
||||
// Increment counts
|
||||
// Contract 1, countA
|
||||
_, incErr = integration.IncrementCount(contract1.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA1.Add(actualCountA1, big.NewInt(1))
|
||||
|
||||
countA1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1AfterIncrement := new(big.Int).SetBytes(countA1AfterIncrementStorage)
|
||||
Expect(countA1AfterIncrement.String()).To(Equal(actualCountA1.String()))
|
||||
prevCountA1.Set(actualCountA1)
|
||||
|
||||
// Contract 2, countA
|
||||
_, incErr = integration.IncrementCount(contract2.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA2.Add(actualCountA2, big.NewInt(1))
|
||||
|
||||
countA2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2AfterIncrement := new(big.Int).SetBytes(countA2AfterIncrementStorage)
|
||||
Expect(countA2AfterIncrement.String()).To(Equal(prevCountA2.String()))
|
||||
|
||||
// Contract 3, countA
|
||||
_, incErr = integration.IncrementCount(contract3.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA3.Add(actualCountA3, big.NewInt(1))
|
||||
|
||||
countA3AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA3AfterIncrement := new(big.Int).SetBytes(countA3AfterIncrementStorage)
|
||||
Expect(countA3AfterIncrement.String()).To(Equal(prevCountA3.String()))
|
||||
})
|
||||
})
|
||||
|
||||
Context("contract added to a non-empty watch-list", func() {
|
||||
It("indexes state only for the watched contracts", func() {
|
||||
operation := statediff.AddAddresses
|
||||
operation := statediff.Add
|
||||
args := []sdtypes.WatchAddressArg{
|
||||
{
|
||||
Address: contract2.Address,
|
||||
@ -264,12 +354,48 @@ var _ = Describe("WatchAddress integration test", func() {
|
||||
balance3AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract3.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance3AfterTransfer.String()).To(Equal(prevBalance3.String()))
|
||||
|
||||
// Increment counts
|
||||
// Contract 1, countA
|
||||
_, incErr = integration.IncrementCount(contract1.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA1.Add(actualCountA1, big.NewInt(1))
|
||||
|
||||
countA1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1AfterIncrement := new(big.Int).SetBytes(countA1AfterIncrementStorage)
|
||||
Expect(countA1AfterIncrement.String()).To(Equal(actualCountA1.String()))
|
||||
prevCountA1.Set(actualCountA1)
|
||||
|
||||
// Contract 2, countA
|
||||
_, incErr = integration.IncrementCount(contract2.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA2.Add(actualCountA2, big.NewInt(1))
|
||||
|
||||
countA2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2AfterIncrement := new(big.Int).SetBytes(countA2AfterIncrementStorage)
|
||||
Expect(countA2AfterIncrement.String()).To(Equal(actualCountA2.String()))
|
||||
prevCountA2.Set(actualCountA2)
|
||||
|
||||
// Contract 3, countA
|
||||
_, incErr = integration.IncrementCount(contract3.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA3.Add(actualCountA3, big.NewInt(1))
|
||||
|
||||
countA3AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA3AfterIncrement := new(big.Int).SetBytes(countA3AfterIncrementStorage)
|
||||
Expect(countA3AfterIncrement.String()).To(Equal(prevCountA3.String()))
|
||||
})
|
||||
})
|
||||
|
||||
Context("contract removed from the watch-list", func() {
|
||||
It("indexes state only for the watched contract", func() {
|
||||
operation := statediff.RemoveAddresses
|
||||
operation := statediff.Remove
|
||||
args := []sdtypes.WatchAddressArg{
|
||||
{
|
||||
Address: contract1.Address,
|
||||
@ -311,12 +437,47 @@ var _ = Describe("WatchAddress integration test", func() {
|
||||
balance3AfterTransfer, err := ipldClient.BalanceAt(ctx, common.HexToAddress(contract3.Address), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance3AfterTransfer.String()).To(Equal(prevBalance3.String()))
|
||||
|
||||
// Increment counts
|
||||
// Contract 1, countA
|
||||
_, incErr = integration.IncrementCount(contract1.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA1.Add(actualCountA1, big.NewInt(1))
|
||||
|
||||
countA1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1AfterIncrement := new(big.Int).SetBytes(countA1AfterIncrementStorage)
|
||||
Expect(countA1AfterIncrement.String()).To(Equal(prevCountA1.String()))
|
||||
|
||||
// Contract 2, countA
|
||||
_, incErr = integration.IncrementCount(contract2.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA2.Add(actualCountA2, big.NewInt(1))
|
||||
|
||||
countA2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2AfterIncrement := new(big.Int).SetBytes(countA2AfterIncrementStorage)
|
||||
Expect(countA2AfterIncrement.String()).To(Equal(actualCountA2.String()))
|
||||
prevCountA2.Set(actualCountA2)
|
||||
|
||||
// Contract 3, countA
|
||||
_, incErr = integration.IncrementCount(contract3.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA3.Add(actualCountA3, big.NewInt(1))
|
||||
|
||||
countA3AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA3AfterIncrement := new(big.Int).SetBytes(countA3AfterIncrementStorage)
|
||||
Expect(countA3AfterIncrement.String()).To(Equal(prevCountA3.String()))
|
||||
})
|
||||
})
|
||||
|
||||
Context("list of watched addresses set", func() {
|
||||
It("indexes state only for the watched contracts", func() {
|
||||
operation := statediff.SetAddresses
|
||||
operation := statediff.Set
|
||||
args := []sdtypes.WatchAddressArg{
|
||||
{
|
||||
Address: contract1.Address,
|
||||
@ -363,12 +524,48 @@ var _ = Describe("WatchAddress integration test", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance3AfterTransfer.String()).To(Equal(actualBalance3.String()))
|
||||
prevBalance3.Set(actualBalance3)
|
||||
|
||||
// Increment counts
|
||||
// Contract 1, countA
|
||||
_, incErr = integration.IncrementCount(contract1.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA1.Add(actualCountA1, big.NewInt(1))
|
||||
|
||||
countA1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1AfterIncrement := new(big.Int).SetBytes(countA1AfterIncrementStorage)
|
||||
Expect(countA1AfterIncrement.String()).To(Equal(actualCountA1.String()))
|
||||
prevCountA1.Set(actualCountA1)
|
||||
|
||||
// Contract 2, countA
|
||||
_, incErr = integration.IncrementCount(contract2.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA2.Add(actualCountA2, big.NewInt(1))
|
||||
|
||||
countA2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2AfterIncrement := new(big.Int).SetBytes(countA2AfterIncrementStorage)
|
||||
Expect(countA2AfterIncrement.String()).To(Equal(prevCountA2.String()))
|
||||
|
||||
// Contract 3, countA
|
||||
_, incErr = integration.IncrementCount(contract3.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA3.Add(actualCountA3, big.NewInt(1))
|
||||
|
||||
countA3AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA3AfterIncrement := new(big.Int).SetBytes(countA3AfterIncrementStorage)
|
||||
Expect(countA3AfterIncrement.String()).To(Equal(actualCountA3.String()))
|
||||
prevCountA3.Set(actualCountA3)
|
||||
})
|
||||
})
|
||||
|
||||
Context("list of watched addresses cleared", func() {
|
||||
It("indexes state for all the contracts", func() {
|
||||
operation := statediff.ClearAddresses
|
||||
operation := statediff.Clear
|
||||
args := []sdtypes.WatchAddressArg{}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, operation, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
@ -407,71 +604,10 @@ var _ = Describe("WatchAddress integration test", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(balance3AfterTransfer.String()).To(Equal(actualBalance3.String()))
|
||||
prevBalance3.Set(actualBalance3)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Describe("watched storage slots", func() {
|
||||
var (
|
||||
incErr error
|
||||
|
||||
prevCountA1 *big.Int
|
||||
prevCountB1 *big.Int
|
||||
prevCountA2 *big.Int
|
||||
prevCountB2 *big.Int
|
||||
|
||||
actualCountA1 *big.Int
|
||||
actualCountB1 *big.Int
|
||||
actualCountA2 *big.Int
|
||||
actualCountB2 *big.Int
|
||||
)
|
||||
|
||||
It("watched addresses test init", func() {
|
||||
// Clear out watched addresses | storage slots
|
||||
err := integration.ClearWatchedAddresses(gethRPCClient)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// Get initial storage values for the contracts
|
||||
// Contract 1, countA
|
||||
actualCountA1 = big.NewInt(0)
|
||||
prevCountA1 = big.NewInt(0)
|
||||
ipldCountA1Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
ipldCountA1 := new(big.Int).SetBytes(ipldCountA1Storage)
|
||||
Expect(ipldCountA1.String()).To(Equal(actualCountA1.String()))
|
||||
|
||||
// Contract 1, countB
|
||||
actualCountB1 = big.NewInt(0)
|
||||
prevCountB1 = big.NewInt(0)
|
||||
ipldCountB1Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
ipldCountB1 := new(big.Int).SetBytes(ipldCountB1Storage)
|
||||
Expect(ipldCountB1.String()).To(Equal(actualCountB1.String()))
|
||||
|
||||
// Contract 2, countA
|
||||
actualCountA2 = big.NewInt(0)
|
||||
prevCountA2 = big.NewInt(0)
|
||||
ipldCountA2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
ipldCountA2 := new(big.Int).SetBytes(ipldCountA2Storage)
|
||||
Expect(ipldCountA2.String()).To(Equal(actualCountA2.String()))
|
||||
|
||||
// Contract 2, countB
|
||||
actualCountB2 = big.NewInt(0)
|
||||
prevCountB2 = big.NewInt(0)
|
||||
ipldCountB2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
ipldCountB2 := new(big.Int).SetBytes(ipldCountB2Storage)
|
||||
Expect(ipldCountB2.String()).To(Equal(actualCountB2.String()))
|
||||
})
|
||||
|
||||
Context("no addresses or storage slots being watched", func() {
|
||||
It("indexes state for all the storage slots", func() {
|
||||
// WatchedAddresses = []
|
||||
// WatchedStorageSlots = []
|
||||
// Increment counts
|
||||
// Contract 1, countA
|
||||
incErr = integration.IncrementCountA(contract1.Address)
|
||||
_, incErr = integration.IncrementCount(contract1.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA1.Add(actualCountA1, big.NewInt(1))
|
||||
@ -482,20 +618,8 @@ var _ = Describe("WatchAddress integration test", func() {
|
||||
Expect(countA1AfterIncrement.String()).To(Equal(actualCountA1.String()))
|
||||
prevCountA1.Set(actualCountA1)
|
||||
|
||||
// Contract 1, countB
|
||||
incErr = integration.IncrementCountB(contract1.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountB1.Add(actualCountB1, big.NewInt(1))
|
||||
|
||||
countB1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB1AfterIncrement := new(big.Int).SetBytes(countB1AfterIncrementStorage)
|
||||
Expect(countB1AfterIncrement.String()).To(Equal(actualCountB1.String()))
|
||||
prevCountB1.Set(actualCountB1)
|
||||
|
||||
// Contract 2, countA
|
||||
incErr = integration.IncrementCountA(contract2.Address)
|
||||
_, incErr = integration.IncrementCount(contract2.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA2.Add(actualCountA2, big.NewInt(1))
|
||||
@ -506,333 +630,17 @@ var _ = Describe("WatchAddress integration test", func() {
|
||||
Expect(countA2AfterIncrement.String()).To(Equal(actualCountA2.String()))
|
||||
prevCountA2.Set(actualCountA2)
|
||||
|
||||
// Contract 2, countB
|
||||
incErr = integration.IncrementCountB(contract2.Address)
|
||||
// Contract 3, countA
|
||||
_, incErr = integration.IncrementCount(contract3.Address, "A")
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountB2.Add(actualCountB2, big.NewInt(1))
|
||||
actualCountA3.Add(actualCountA3, big.NewInt(1))
|
||||
|
||||
countB2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countBIndex), nil)
|
||||
countA3AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB2AfterIncrement := new(big.Int).SetBytes(countB2AfterIncrementStorage)
|
||||
Expect(countB2AfterIncrement.String()).To(Equal(actualCountB2.String()))
|
||||
prevCountB2.Set(actualCountB2)
|
||||
})
|
||||
})
|
||||
|
||||
Context("one storage slot being watched", func() {
|
||||
It("indexes state only for the watched storage slot", func() {
|
||||
operation := statediff.AddStorageSlots
|
||||
args := []sdtypes.WatchAddressArg{
|
||||
{
|
||||
Address: countAStorageHash.Hex(),
|
||||
CreatedAt: uint64(contract1.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, operation, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// WatchedAddresses = []
|
||||
// WatchedStorageSlots = [countA]
|
||||
// Increment counts
|
||||
// Contract 1, countA
|
||||
incErr = integration.IncrementCountA(contract1.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA1.Add(actualCountA1, big.NewInt(1))
|
||||
|
||||
countA1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1AfterIncrement := new(big.Int).SetBytes(countA1AfterIncrementStorage)
|
||||
Expect(countA1AfterIncrement.String()).To(Equal(actualCountA1.String()))
|
||||
prevCountA1.Set(actualCountA1)
|
||||
|
||||
// Contract 1, countB
|
||||
incErr = integration.IncrementCountB(contract1.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountB1.Add(actualCountB1, big.NewInt(1))
|
||||
|
||||
countB1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB1AfterIncrement := new(big.Int).SetBytes(countB1AfterIncrementStorage)
|
||||
Expect(countB1AfterIncrement.String()).To(Equal(prevCountB1.String()))
|
||||
|
||||
// Contract 2, countA
|
||||
incErr = integration.IncrementCountA(contract2.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA2.Add(actualCountA2, big.NewInt(1))
|
||||
|
||||
countA2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2AfterIncrement := new(big.Int).SetBytes(countA2AfterIncrementStorage)
|
||||
Expect(countA2AfterIncrement.String()).To(Equal(actualCountA2.String()))
|
||||
prevCountA2.Set(actualCountA2)
|
||||
|
||||
// Contract 2, countB
|
||||
incErr = integration.IncrementCountB(contract2.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountB2.Add(actualCountB2, big.NewInt(1))
|
||||
|
||||
countB2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB2AfterIncrement := new(big.Int).SetBytes(countB2AfterIncrementStorage)
|
||||
Expect(countB2AfterIncrement.String()).To(Equal(prevCountB2.String()))
|
||||
})
|
||||
})
|
||||
|
||||
Context("list of watched storage slots set", func() {
|
||||
It("indexes state only for the watched storage slots", func() {
|
||||
operation := statediff.SetStorageSlots
|
||||
args := []sdtypes.WatchAddressArg{
|
||||
{
|
||||
Address: countAStorageHash.Hex(),
|
||||
CreatedAt: uint64(contract1.BlockNumber),
|
||||
},
|
||||
{
|
||||
Address: countBStorageHash.Hex(),
|
||||
CreatedAt: uint64(contract2.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, operation, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// WatchedAddresses = []
|
||||
// WatchedStorageSlots = [countA, countB]
|
||||
// Increment counts
|
||||
// Contract 1, countA
|
||||
incErr = integration.IncrementCountA(contract1.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA1.Add(actualCountA1, big.NewInt(1))
|
||||
|
||||
countA1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1AfterIncrement := new(big.Int).SetBytes(countA1AfterIncrementStorage)
|
||||
Expect(countA1AfterIncrement.String()).To(Equal(actualCountA1.String()))
|
||||
prevCountA1.Set(actualCountA1)
|
||||
|
||||
// Contract 1, countB
|
||||
incErr = integration.IncrementCountB(contract1.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountB1.Add(actualCountB1, big.NewInt(1))
|
||||
|
||||
countB1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB1AfterIncrement := new(big.Int).SetBytes(countB1AfterIncrementStorage)
|
||||
Expect(countB1AfterIncrement.String()).To(Equal(actualCountB1.String()))
|
||||
prevCountB1.Set(actualCountB1)
|
||||
|
||||
// Contract 2, countA
|
||||
incErr = integration.IncrementCountA(contract2.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA2.Add(actualCountA2, big.NewInt(1))
|
||||
|
||||
countA2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2AfterIncrement := new(big.Int).SetBytes(countA2AfterIncrementStorage)
|
||||
Expect(countA2AfterIncrement.String()).To(Equal(actualCountA2.String()))
|
||||
prevCountA2.Set(actualCountA2)
|
||||
|
||||
// Contract 2, countB
|
||||
incErr = integration.IncrementCountB(contract2.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountB2.Add(actualCountB2, big.NewInt(1))
|
||||
|
||||
countB2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB2AfterIncrement := new(big.Int).SetBytes(countB2AfterIncrementStorage)
|
||||
Expect(countB2AfterIncrement.String()).To(Equal(actualCountB2.String()))
|
||||
prevCountB2.Set(actualCountB2)
|
||||
})
|
||||
})
|
||||
|
||||
Context("storage slot removed from the watch-list", func() {
|
||||
It("indexes state only for the watched storage slots", func() {
|
||||
operation := statediff.RemoveStorageSlots
|
||||
args := []sdtypes.WatchAddressArg{
|
||||
{
|
||||
Address: countAStorageHash.Hex(),
|
||||
CreatedAt: uint64(contract1.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, operation, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// WatchedAddresses = []
|
||||
// WatchedStorageSlots = [countB]
|
||||
// Increment counts
|
||||
// Contract 1, countA
|
||||
incErr = integration.IncrementCountA(contract1.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA1.Add(actualCountA1, big.NewInt(1))
|
||||
|
||||
countA1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1AfterIncrement := new(big.Int).SetBytes(countA1AfterIncrementStorage)
|
||||
Expect(countA1AfterIncrement.String()).To(Equal(prevCountA1.String()))
|
||||
|
||||
// Contract 1, countB
|
||||
incErr = integration.IncrementCountB(contract1.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountB1.Add(actualCountB1, big.NewInt(1))
|
||||
|
||||
countB1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB1AfterIncrement := new(big.Int).SetBytes(countB1AfterIncrementStorage)
|
||||
Expect(countB1AfterIncrement.String()).To(Equal(actualCountB1.String()))
|
||||
prevCountB1.Set(actualCountB1)
|
||||
|
||||
// Contract 2, countA
|
||||
incErr = integration.IncrementCountA(contract2.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA2.Add(actualCountA2, big.NewInt(1))
|
||||
|
||||
countA2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2AfterIncrement := new(big.Int).SetBytes(countA2AfterIncrementStorage)
|
||||
Expect(countA2AfterIncrement.String()).To(Equal(prevCountA2.String()))
|
||||
|
||||
// Contract 2, countB
|
||||
incErr = integration.IncrementCountB(contract2.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountB2.Add(actualCountB2, big.NewInt(1))
|
||||
|
||||
countB2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB2AfterIncrement := new(big.Int).SetBytes(countB2AfterIncrementStorage)
|
||||
Expect(countB2AfterIncrement.String()).To(Equal(actualCountB2.String()))
|
||||
prevCountB2.Set(actualCountB2)
|
||||
})
|
||||
})
|
||||
|
||||
Context("one contract and one storage slot being watched", func() {
|
||||
It("indexes state only for the watched storage slots of watched contracts", func() {
|
||||
operation := statediff.SetAddresses
|
||||
args := []sdtypes.WatchAddressArg{
|
||||
{
|
||||
Address: contract1.Address,
|
||||
CreatedAt: uint64(contract1.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, operation, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// WatchedAddresses = [Contract1]
|
||||
// WatchedStorageSlots = [countB]
|
||||
// Increment counts
|
||||
// Contract 1, countA
|
||||
incErr = integration.IncrementCountA(contract1.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA1.Add(actualCountA1, big.NewInt(1))
|
||||
|
||||
countA1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1AfterIncrement := new(big.Int).SetBytes(countA1AfterIncrementStorage)
|
||||
Expect(countA1AfterIncrement.String()).To(Equal(prevCountA1.String()))
|
||||
|
||||
// Contract 1, countB
|
||||
incErr = integration.IncrementCountB(contract1.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountB1.Add(actualCountB1, big.NewInt(1))
|
||||
|
||||
countB1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB1AfterIncrement := new(big.Int).SetBytes(countB1AfterIncrementStorage)
|
||||
Expect(countB1AfterIncrement.String()).To(Equal(actualCountB1.String()))
|
||||
prevCountB1.Set(actualCountB1)
|
||||
|
||||
// Contract 2, countA
|
||||
incErr = integration.IncrementCountA(contract2.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA2.Add(actualCountA2, big.NewInt(1))
|
||||
|
||||
countA2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2AfterIncrement := new(big.Int).SetBytes(countA2AfterIncrementStorage)
|
||||
Expect(countA2AfterIncrement.String()).To(Equal(prevCountA2.String()))
|
||||
|
||||
// Contract 2, countB
|
||||
incErr = integration.IncrementCountB(contract2.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountB2.Add(actualCountB2, big.NewInt(1))
|
||||
|
||||
countB2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB2AfterIncrement := new(big.Int).SetBytes(countB2AfterIncrementStorage)
|
||||
Expect(countB2AfterIncrement.String()).To(Equal(prevCountB2.String()))
|
||||
})
|
||||
})
|
||||
|
||||
Context("list of watched storage slots cleared", func() {
|
||||
It("indexes state for all the storage slots of watched contracts", func() {
|
||||
operation := statediff.ClearStorageSlots
|
||||
args := []sdtypes.WatchAddressArg{}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, operation, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// WatchedAddresses = [Contract1]
|
||||
// WatchedStorageSlots = []
|
||||
// Increment counts
|
||||
// Contract 1, countA
|
||||
incErr = integration.IncrementCountA(contract1.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA1.Add(actualCountA1, big.NewInt(1))
|
||||
|
||||
countA1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1AfterIncrement := new(big.Int).SetBytes(countA1AfterIncrementStorage)
|
||||
Expect(countA1AfterIncrement.String()).To(Equal(actualCountA1.String()))
|
||||
prevCountA1.Set(actualCountA1)
|
||||
|
||||
// Contract 1, countB
|
||||
incErr = integration.IncrementCountB(contract1.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountB1.Add(actualCountB1, big.NewInt(1))
|
||||
|
||||
countB1AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract1.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB1AfterIncrement := new(big.Int).SetBytes(countB1AfterIncrementStorage)
|
||||
Expect(countB1AfterIncrement.String()).To(Equal(actualCountB1.String()))
|
||||
prevCountB1.Set(actualCountB1)
|
||||
|
||||
// Contract 2, countA
|
||||
incErr = integration.IncrementCountA(contract2.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountA2.Add(actualCountA2, big.NewInt(1))
|
||||
|
||||
countA2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2AfterIncrement := new(big.Int).SetBytes(countA2AfterIncrementStorage)
|
||||
Expect(countA2AfterIncrement.String()).To(Equal(prevCountA2.String()))
|
||||
|
||||
// Contract 2, countB
|
||||
incErr = integration.IncrementCountB(contract2.Address)
|
||||
time.Sleep(sleepInterval)
|
||||
Expect(incErr).ToNot(HaveOccurred())
|
||||
actualCountB2.Add(actualCountB2, big.NewInt(1))
|
||||
|
||||
countB2AfterIncrementStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract2.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB2AfterIncrement := new(big.Int).SetBytes(countB2AfterIncrementStorage)
|
||||
Expect(countB2AfterIncrement.String()).To(Equal(prevCountB2.String()))
|
||||
})
|
||||
countA3AfterIncrement := new(big.Int).SetBytes(countA3AfterIncrementStorage)
|
||||
Expect(countA3AfterIncrement.String()).To(Equal(actualCountA3.String()))
|
||||
prevCountA3.Set(actualCountA3)
|
||||
})
|
||||
})
|
||||
|
||||
@ -851,7 +659,7 @@ var _ = Describe("WatchAddress integration test", func() {
|
||||
})
|
||||
|
||||
It("returns an error on args of invalid type", func() {
|
||||
operation := statediff.AddAddresses
|
||||
operation := statediff.Add
|
||||
args := []string{"WrongArg"}
|
||||
|
||||
gethErr := gethRPCClient.Call(nil, gethMethod, operation, args)
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/statediff"
|
||||
@ -18,12 +17,6 @@ import (
|
||||
integration "github.com/vulcanize/ipld-eth-server/test"
|
||||
)
|
||||
|
||||
var (
|
||||
ctx = context.Background()
|
||||
|
||||
ipldClient *ethclient.Client
|
||||
)
|
||||
|
||||
var _ = Describe("Watched address gap filling service integration test", func() {
|
||||
dbWrite, err := strconv.ParseBool(os.Getenv("DB_WRITE"))
|
||||
Expect(err).To(BeNil())
|
||||
@ -39,42 +32,33 @@ var _ = Describe("Watched address gap filling service integration test", func()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
ipldEthHttpPath := "http://127.0.0.1:8081"
|
||||
ipldClient, err = ethclient.Dial(ipldEthHttpPath)
|
||||
ipldClient, err := ethclient.Dial(ipldEthHttpPath)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
ipldRPCClient, err := rpc.Dial(ipldEthHttpPath)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
var (
|
||||
ctx = context.Background()
|
||||
|
||||
contractErr error
|
||||
txErr error
|
||||
|
||||
GLD1 *integration.ContractDeployed
|
||||
GLD2 *integration.ContractDeployed
|
||||
SLV1 *integration.ContractDeployed
|
||||
SLV2 *integration.ContractDeployed
|
||||
SLV3 *integration.ContractDeployed
|
||||
|
||||
countAIndex string
|
||||
countBIndex string
|
||||
countAStorageHash common.Hash
|
||||
countBStorageHash common.Hash
|
||||
|
||||
totalSupplyIndex = "0x2"
|
||||
totalSuppyStorageHash = crypto.Keccak256Hash(common.HexToHash(totalSupplyIndex).Bytes())
|
||||
|
||||
oldCountA1 = big.NewInt(0)
|
||||
oldCountB1 = big.NewInt(0)
|
||||
oldCountA2 = big.NewInt(0)
|
||||
oldCountB2 = big.NewInt(0)
|
||||
oldCountA3 = big.NewInt(0)
|
||||
oldCountB3 = big.NewInt(0)
|
||||
|
||||
updatedCountA1 = big.NewInt(1)
|
||||
updatedCountB1 = big.NewInt(1)
|
||||
updatedCountA2 = big.NewInt(1)
|
||||
updatedCountB2 = big.NewInt(1)
|
||||
updatedCountA3 = big.NewInt(1)
|
||||
updatedCountB3 = big.NewInt(1)
|
||||
|
||||
SLV2CountBIncrementedAt *integration.CountIncremented
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
@ -84,7 +68,7 @@ var _ = Describe("Watched address gap filling service integration test", func()
|
||||
})
|
||||
|
||||
It("test init", func() {
|
||||
// Clear out watched addresses | storage slots
|
||||
// Clear out watched addresses
|
||||
err := integration.ClearWatchedAddresses(gethRPCClient)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
@ -93,7 +77,7 @@ var _ = Describe("Watched address gap filling service integration test", func()
|
||||
Expect(contractErr).ToNot(HaveOccurred())
|
||||
|
||||
// Watch GLD1 contract
|
||||
operation := statediff.AddAddresses
|
||||
operation := statediff.Add
|
||||
args := []sdtypes.WatchAddressArg{
|
||||
{
|
||||
Address: GLD1.Address,
|
||||
@ -103,49 +87,33 @@ var _ = Describe("Watched address gap filling service integration test", func()
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, operation, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// Deploy a GLD contract
|
||||
GLD2, contractErr = integration.DeployContract()
|
||||
Expect(contractErr).ToNot(HaveOccurred())
|
||||
|
||||
// Deploy three SLV contracts and update storage slots
|
||||
// Deploy two SLV contracts and update storage slots
|
||||
SLV1, contractErr = integration.DeploySLVContract()
|
||||
Expect(contractErr).ToNot(HaveOccurred())
|
||||
|
||||
txErr = integration.IncrementCountA(SLV1.Address)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
txErr = integration.IncrementCountB(SLV1.Address)
|
||||
_, txErr = integration.IncrementCount(SLV1.Address, "A")
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
|
||||
SLV2, contractErr = integration.DeploySLVContract()
|
||||
Expect(contractErr).ToNot(HaveOccurred())
|
||||
|
||||
txErr = integration.IncrementCountA(SLV2.Address)
|
||||
_, txErr = integration.IncrementCount(SLV2.Address, "A")
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
txErr = integration.IncrementCountB(SLV2.Address)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
|
||||
SLV3, contractErr = integration.DeploySLVContract()
|
||||
Expect(contractErr).ToNot(HaveOccurred())
|
||||
|
||||
txErr = integration.IncrementCountA(SLV3.Address)
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
txErr = integration.IncrementCountB(SLV3.Address)
|
||||
SLV2CountBIncrementedAt, txErr = integration.IncrementCount(SLV2.Address, "B")
|
||||
Expect(txErr).ToNot(HaveOccurred())
|
||||
|
||||
// Get storage slot keys
|
||||
storageSlotAKey, err := integration.GetStorageSlotKey("SLVToken", "countA")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countAIndex = storageSlotAKey.Key
|
||||
countAStorageHash = crypto.Keccak256Hash(common.HexToHash(countAIndex).Bytes())
|
||||
|
||||
storageSlotBKey, err := integration.GetStorageSlotKey("SLVToken", "countB")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countBIndex = storageSlotBKey.Key
|
||||
countBStorageHash = crypto.Keccak256Hash(common.HexToHash(countBIndex).Bytes())
|
||||
})
|
||||
|
||||
defer It("test cleanup", func() {
|
||||
// Clear out watched addresses | storage slots
|
||||
// Clear out watched addresses
|
||||
err := integration.ClearWatchedAddresses(gethRPCClient)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
@ -153,19 +121,12 @@ var _ = Describe("Watched address gap filling service integration test", func()
|
||||
Context("previously unwatched contract watched", func() {
|
||||
It("indexes state only for watched contract", func() {
|
||||
// WatchedAddresses = [GLD1]
|
||||
// WatchedStorageSlots = []
|
||||
// SLV1, countA
|
||||
countA1Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1 := new(big.Int).SetBytes(countA1Storage)
|
||||
Expect(countA1.String()).To(Equal(oldCountA1.String()))
|
||||
|
||||
// SLV1, countB
|
||||
countB1Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV1.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB1 := new(big.Int).SetBytes(countB1Storage)
|
||||
Expect(countB1.String()).To(Equal(oldCountB1.String()))
|
||||
|
||||
// SLV2, countA
|
||||
countA2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@ -177,18 +138,6 @@ var _ = Describe("Watched address gap filling service integration test", func()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB2 := new(big.Int).SetBytes(countB2Storage)
|
||||
Expect(countB2.String()).To(Equal(oldCountB2.String()))
|
||||
|
||||
// SLV3, countA
|
||||
countA3Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA3 := new(big.Int).SetBytes(countA3Storage)
|
||||
Expect(countA3.String()).To(Equal(oldCountA3.String()))
|
||||
|
||||
// SLV3, countB
|
||||
countB3Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV3.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB3 := new(big.Int).SetBytes(countB3Storage)
|
||||
Expect(countB3.String()).To(Equal(oldCountB3.String()))
|
||||
})
|
||||
|
||||
It("indexes past state on watching a contract", func() {
|
||||
@ -199,26 +148,19 @@ var _ = Describe("Watched address gap filling service integration test", func()
|
||||
CreatedAt: uint64(SLV1.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, statediff.AddAddresses, args)
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, statediff.Add, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// Sleep for service interval + few extra seconds
|
||||
time.Sleep(time.Duration(serviceInterval+2) * time.Second)
|
||||
|
||||
// WatchedAddresses = [GLD1, SLV1]
|
||||
// WatchedStorageSlots = []
|
||||
// SLV1, countA
|
||||
countA1Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV1.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA1 := new(big.Int).SetBytes(countA1Storage)
|
||||
Expect(countA1.String()).To(Equal(updatedCountA1.String()))
|
||||
|
||||
// SLV1, countB
|
||||
countB1Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV1.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB1 := new(big.Int).SetBytes(countB1Storage)
|
||||
Expect(countB1.String()).To(Equal(updatedCountB1.String()))
|
||||
|
||||
// SLV2, countA
|
||||
countA2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@ -230,142 +172,57 @@ var _ = Describe("Watched address gap filling service integration test", func()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB2 := new(big.Int).SetBytes(countB2Storage)
|
||||
Expect(countB2.String()).To(Equal(oldCountB2.String()))
|
||||
|
||||
// SLV3, countA
|
||||
countA3Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA3 := new(big.Int).SetBytes(countA3Storage)
|
||||
Expect(countA3.String()).To(Equal(oldCountA3.String()))
|
||||
|
||||
// SLV3, countB
|
||||
countB3Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV3.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB3 := new(big.Int).SetBytes(countB3Storage)
|
||||
Expect(countB3.String()).To(Equal(oldCountB3.String()))
|
||||
})
|
||||
})
|
||||
|
||||
Context("one storage slot being watched", func() {
|
||||
It("indexer past state only for watched storage slots of watched contracts", func() {
|
||||
// Watch countA
|
||||
Context("previously unwatched contract watched (different 'created_at')", func() {
|
||||
It("indexes past state from 'created_at' onwards on watching a contract", func() {
|
||||
// Watch SLV2 (created_at -> countB incremented) contract
|
||||
args := []sdtypes.WatchAddressArg{
|
||||
{
|
||||
Address: countAStorageHash.Hex(),
|
||||
CreatedAt: uint64(SLV1.BlockNumber),
|
||||
Address: SLV2.Address,
|
||||
CreatedAt: uint64(SLV2CountBIncrementedAt.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, statediff.AddStorageSlots, args)
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, statediff.Add, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// Watch SLV2 contract
|
||||
args = []sdtypes.WatchAddressArg{
|
||||
// Sleep for service interval + few extra seconds
|
||||
time.Sleep(time.Duration(serviceInterval+2) * time.Second)
|
||||
|
||||
// WatchedAddresses = [GLD1, SLV1, SLV2]
|
||||
// SLV2, countA
|
||||
countA2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2 := new(big.Int).SetBytes(countA2Storage)
|
||||
Expect(countA2.String()).To(Equal(oldCountA2.String()))
|
||||
|
||||
// SLV2, countB
|
||||
countB2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV2.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB2 := new(big.Int).SetBytes(countB2Storage)
|
||||
Expect(countB2.String()).To(Equal(updatedCountB2.String()))
|
||||
})
|
||||
|
||||
It("indexes missing past state on watching a contract from an earlier 'created_at'", func() {
|
||||
// Clear out watched addresses
|
||||
err := integration.ClearWatchedAddresses(gethRPCClient)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// Watch SLV2 (created_at -> deployment) contract
|
||||
args := []sdtypes.WatchAddressArg{
|
||||
{
|
||||
Address: SLV2.Address,
|
||||
CreatedAt: uint64(SLV2.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr = ipldRPCClient.Call(nil, ipldMethod, statediff.AddAddresses, args)
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, statediff.Add, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// Sleep for service interval + few extra seconds
|
||||
time.Sleep(time.Duration(serviceInterval+2) * time.Second)
|
||||
|
||||
// WatchedAddresses = [GLD1, SLV1, SLV2]
|
||||
// WatchedStorageSlots = [countA]
|
||||
// SLV2, countA
|
||||
countA2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2 := new(big.Int).SetBytes(countA2Storage)
|
||||
Expect(countA2.String()).To(Equal(updatedCountA2.String()))
|
||||
|
||||
// SLV2, countB
|
||||
countB2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV2.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB2 := new(big.Int).SetBytes(countB2Storage)
|
||||
Expect(countB2.String()).To(Equal(oldCountB2.String()))
|
||||
|
||||
// SLV3, countA
|
||||
countA3Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA3 := new(big.Int).SetBytes(countA3Storage)
|
||||
Expect(countA3.String()).To(Equal(oldCountA3.String()))
|
||||
|
||||
// SLV3, countB
|
||||
countB3Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV3.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB3 := new(big.Int).SetBytes(countB3Storage)
|
||||
Expect(countB3.String()).To(Equal(oldCountB3.String()))
|
||||
})
|
||||
})
|
||||
|
||||
Context("previously unwatched storage slot watched", func() {
|
||||
It("indexes past state only for watched storage slots updated after created at", func() {
|
||||
// Watch countB with created_at = SLV3.BlockNumber
|
||||
args := []sdtypes.WatchAddressArg{
|
||||
{
|
||||
Address: countBStorageHash.Hex(),
|
||||
CreatedAt: uint64(SLV3.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, statediff.AddStorageSlots, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// Sleep for service interval + few extra seconds
|
||||
time.Sleep(time.Duration(serviceInterval+2) * time.Second)
|
||||
|
||||
// WatchedAddresses = [GLD1, SLV1, SLV2]
|
||||
// WatchedStorageSlots = [countA, countB] (countB -> created_at = SLV3.BlockNumber)
|
||||
// SLV2, countA
|
||||
countA2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA2 := new(big.Int).SetBytes(countA2Storage)
|
||||
Expect(countA2.String()).To(Equal(updatedCountA2.String()))
|
||||
|
||||
// SLV2, countB
|
||||
countB2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV2.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB2 := new(big.Int).SetBytes(countB2Storage)
|
||||
Expect(countB2.String()).To(Equal(oldCountB2.String()))
|
||||
|
||||
// SLV3, countA
|
||||
countA3Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA3 := new(big.Int).SetBytes(countA3Storage)
|
||||
Expect(countA3.String()).To(Equal(oldCountA3.String()))
|
||||
|
||||
// SLV3, countB
|
||||
countB3Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV3.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB3 := new(big.Int).SetBytes(countB3Storage)
|
||||
Expect(countB3.String()).To(Equal(oldCountB3.String()))
|
||||
})
|
||||
|
||||
It("indexes past state for watched storage slots of watched contracts", func() {
|
||||
// Unwatch countB
|
||||
args := []sdtypes.WatchAddressArg{
|
||||
{
|
||||
Address: countBStorageHash.Hex(),
|
||||
CreatedAt: uint64(SLV3.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, statediff.RemoveStorageSlots, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// Watch countB with created_at = SLV1.BlockNumber
|
||||
args = []sdtypes.WatchAddressArg{
|
||||
{
|
||||
Address: countBStorageHash.Hex(),
|
||||
CreatedAt: uint64(SLV1.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr = ipldRPCClient.Call(nil, ipldMethod, statediff.AddStorageSlots, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// Sleep for service interval + few extra seconds
|
||||
time.Sleep(time.Duration(serviceInterval+2) * time.Second)
|
||||
|
||||
// WatchedAddresses = [GLD1, SLV1, SLV2]
|
||||
// WatchedStorageSlots = [countA, countB] (countB -> created_at = SLV1.BlockNumber)
|
||||
// WatchedAddresses = [SLV2]
|
||||
// SLV2, countA
|
||||
countA2Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV2.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@ -377,66 +234,6 @@ var _ = Describe("Watched address gap filling service integration test", func()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB2 := new(big.Int).SetBytes(countB2Storage)
|
||||
Expect(countB2.String()).To(Equal(updatedCountB2.String()))
|
||||
|
||||
// SLV3, countA
|
||||
countA3Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA3 := new(big.Int).SetBytes(countA3Storage)
|
||||
Expect(countA3.String()).To(Equal(oldCountA3.String()))
|
||||
|
||||
// SLV3, countB
|
||||
countB3Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV3.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB3 := new(big.Int).SetBytes(countB3Storage)
|
||||
Expect(countB3.String()).To(Equal(oldCountB3.String()))
|
||||
})
|
||||
})
|
||||
|
||||
Context("contract watched along with other contract and its storage slots", func() {
|
||||
It("indexes past state for watched storage slots of watched contracts", func() {
|
||||
// Watch totalSupply
|
||||
args := []sdtypes.WatchAddressArg{
|
||||
{
|
||||
Address: totalSuppyStorageHash.Hex(),
|
||||
CreatedAt: uint64(GLD1.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr := ipldRPCClient.Call(nil, ipldMethod, statediff.AddStorageSlots, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// Watch GLD2 and SLV3 contracts
|
||||
args = []sdtypes.WatchAddressArg{
|
||||
{
|
||||
Address: GLD2.Address,
|
||||
CreatedAt: uint64(GLD2.BlockNumber),
|
||||
},
|
||||
{
|
||||
Address: SLV3.Address,
|
||||
CreatedAt: uint64(SLV3.BlockNumber),
|
||||
},
|
||||
}
|
||||
ipldErr = ipldRPCClient.Call(nil, ipldMethod, statediff.AddAddresses, args)
|
||||
Expect(ipldErr).ToNot(HaveOccurred())
|
||||
|
||||
// Sleep for service interval + few extra seconds
|
||||
time.Sleep(time.Duration(serviceInterval+2) * time.Second)
|
||||
|
||||
// WatchedAddresses = [GLD1, SLV1, SLV2, GLD2, SLV3]
|
||||
// WatchedStorageSlots = [countA, countB, totalSupply]
|
||||
// SLV3, countA
|
||||
countA3Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV3.Address), common.HexToHash(countAIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countA3 := new(big.Int).SetBytes(countA3Storage)
|
||||
Expect(countA3.String()).To(Equal(updatedCountA3.String()))
|
||||
|
||||
// SLV3, countB
|
||||
countB3Storage, err := ipldClient.StorageAt(ctx, common.HexToAddress(SLV3.Address), common.HexToHash(countBIndex), nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
countB3 := new(big.Int).SetBytes(countB3Storage)
|
||||
Expect(countB3.String()).To(Equal(updatedCountB3.String()))
|
||||
})
|
||||
})
|
||||
|
||||
// TODO:
|
||||
// Add test: watched storage slot not having any previously watched related contracts.
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user