2020-10-15 22:31:52 +00:00
|
|
|
package accounts
|
2020-08-20 17:53:09 +00:00
|
|
|
|
|
|
|
import (
|
2023-04-17 18:01:13 +00:00
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"path"
|
2020-08-20 17:53:09 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-04-17 18:01:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/build/bazel"
|
2023-03-17 18:52:56 +00:00
|
|
|
fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
|
2023-04-17 18:01:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/io/file"
|
|
|
|
eth "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
2023-03-17 18:52:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/require"
|
2021-02-01 19:00:06 +00:00
|
|
|
"github.com/sirupsen/logrus/hooks/test"
|
2020-08-20 17:53:09 +00:00
|
|
|
)
|
|
|
|
|
2021-02-01 19:00:06 +00:00
|
|
|
func TestDisplayExitInfo(t *testing.T) {
|
|
|
|
logHook := test.NewGlobal()
|
|
|
|
key := []byte("0x123456")
|
|
|
|
displayExitInfo([][]byte{key}, []string{string(key)})
|
|
|
|
assert.LogsContain(t, logHook, "https://beaconcha.in/validator/3078313233343536")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDisplayExitInfo_NoKeys(t *testing.T) {
|
|
|
|
logHook := test.NewGlobal()
|
|
|
|
displayExitInfo([][]byte{}, []string{})
|
|
|
|
assert.LogsContain(t, logHook, "No successful voluntary exits")
|
|
|
|
}
|
2021-05-18 17:17:42 +00:00
|
|
|
|
|
|
|
func TestPrepareAllKeys(t *testing.T) {
|
|
|
|
key1 := bytesutil.ToBytes48([]byte("key1"))
|
|
|
|
key2 := bytesutil.ToBytes48([]byte("key2"))
|
2022-01-06 17:33:08 +00:00
|
|
|
raw, formatted := prepareAllKeys([][fieldparams.BLSPubkeyLength]byte{key1, key2})
|
2021-05-18 17:17:42 +00:00
|
|
|
require.Equal(t, 2, len(raw))
|
|
|
|
require.Equal(t, 2, len(formatted))
|
|
|
|
assert.DeepEqual(t, bytesutil.ToBytes48([]byte{107, 101, 121, 49}), bytesutil.ToBytes48(raw[0]))
|
|
|
|
assert.DeepEqual(t, bytesutil.ToBytes48([]byte{107, 101, 121, 50}), bytesutil.ToBytes48(raw[1]))
|
|
|
|
assert.Equal(t, "0x6b6579310000", formatted[0])
|
|
|
|
assert.Equal(t, "0x6b6579320000", formatted[1])
|
|
|
|
}
|
2023-04-17 18:01:13 +00:00
|
|
|
|
|
|
|
func TestWriteSignedVoluntaryExitJSON(t *testing.T) {
|
|
|
|
sve := ð.SignedVoluntaryExit{
|
|
|
|
Exit: ð.VoluntaryExit{
|
|
|
|
Epoch: 5,
|
|
|
|
ValidatorIndex: 300,
|
|
|
|
},
|
|
|
|
Signature: []byte{0x01, 0x02},
|
|
|
|
}
|
|
|
|
|
|
|
|
output := path.Join(bazel.TestTmpDir(), "TestWriteSignedVoluntaryExitJSON")
|
|
|
|
require.NoError(t, writeSignedVoluntaryExitJSON(context.Background(), sve, output))
|
|
|
|
|
|
|
|
b, err := file.ReadFileAsBytes(path.Join(output, "validator-exit-300.json"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
svej := &apimiddleware.SignedVoluntaryExitJson{}
|
|
|
|
require.NoError(t, json.Unmarshal(b, svej))
|
|
|
|
|
|
|
|
require.Equal(t, fmt.Sprintf("%d", sve.Exit.Epoch), svej.Exit.Epoch)
|
|
|
|
require.Equal(t, fmt.Sprintf("%d", sve.Exit.ValidatorIndex), svej.Exit.ValidatorIndex)
|
|
|
|
require.Equal(t, "0x0102", svej.Signature)
|
|
|
|
}
|