2019-08-21 21:11:50 +00:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2022-08-16 12:20:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
2019-08-21 21:11:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStore_DepositContract(t *testing.T) {
|
|
|
|
db := setupDB(t)
|
|
|
|
ctx := context.Background()
|
|
|
|
contractAddress := common.Address{1, 2, 3}
|
|
|
|
retrieved, err := db.DepositContractAddress(ctx)
|
2020-08-08 18:39:01 +00:00
|
|
|
require.NoError(t, err)
|
2021-01-05 13:29:46 +00:00
|
|
|
assert.DeepEqual(t, []uint8(nil), retrieved, "Expected nil contract address")
|
2020-08-08 18:39:01 +00:00
|
|
|
require.NoError(t, db.SaveDepositContractAddress(ctx, contractAddress))
|
2019-08-21 21:11:50 +00:00
|
|
|
retrieved, err = db.DepositContractAddress(ctx)
|
2020-08-08 18:39:01 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, contractAddress, common.BytesToAddress(retrieved), "Unexpected address")
|
2019-08-21 21:11:50 +00:00
|
|
|
otherAddress := common.Address{4, 5, 6}
|
2020-08-08 18:39:01 +00:00
|
|
|
err = db.SaveDepositContractAddress(ctx, otherAddress)
|
|
|
|
want := "cannot override deposit contract address"
|
|
|
|
assert.ErrorContains(t, want, err, "Should not have been able to override old deposit contract address")
|
2019-08-21 21:11:50 +00:00
|
|
|
}
|