mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package tos
|
|
|
|
import (
|
|
"flag"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/cmd"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
func TestVerifyTosAcceptedOrPrompt(t *testing.T) {
|
|
app := cli.App{}
|
|
set := flag.NewFlagSet("test", 0)
|
|
set.String(cmd.DataDirFlag.Name, "./tmpdir/", "")
|
|
context := cli.NewContext(&app, set, nil)
|
|
|
|
// replacing stdin
|
|
tmpfile, err := os.CreateTemp("", "tmp")
|
|
require.NoError(t, err)
|
|
origStdin := os.Stdin
|
|
os.Stdin = tmpfile
|
|
defer func() { os.Stdin = origStdin }()
|
|
|
|
// userprompt decline
|
|
_, err = tmpfile.Write([]byte("decline"))
|
|
require.NoError(t, err)
|
|
_, err = tmpfile.Seek(0, 0)
|
|
require.NoError(t, err)
|
|
require.ErrorContains(t, "you have to accept Terms and Conditions", VerifyTosAcceptedOrPrompt(context))
|
|
|
|
// userprompt accept
|
|
err = tmpfile.Truncate(0)
|
|
require.NoError(t, err)
|
|
_, err = tmpfile.Seek(0, 0)
|
|
require.NoError(t, err)
|
|
_, err = tmpfile.Write([]byte("accept"))
|
|
require.NoError(t, err)
|
|
_, err = tmpfile.Seek(0, 0)
|
|
require.NoError(t, err)
|
|
require.NoError(t, VerifyTosAcceptedOrPrompt(context))
|
|
require.NoError(t, os.Remove(filepath.Join(context.String(cmd.DataDirFlag.Name), acceptTosFilename)))
|
|
|
|
require.NoError(t, tmpfile.Close())
|
|
require.NoError(t, os.Remove(tmpfile.Name()))
|
|
|
|
// saved in file
|
|
require.NoError(t, os.WriteFile(filepath.Join(context.String(cmd.DataDirFlag.Name), acceptTosFilename), []byte(""), 0666))
|
|
require.NoError(t, VerifyTosAcceptedOrPrompt(context))
|
|
require.NoError(t, os.RemoveAll(context.String(cmd.DataDirFlag.Name)))
|
|
|
|
// flag is set
|
|
set.Bool(cmd.AcceptTosFlag.Name, true, "")
|
|
require.NoError(t, VerifyTosAcceptedOrPrompt(context))
|
|
require.NoError(t, os.RemoveAll(context.String(cmd.DataDirFlag.Name)))
|
|
}
|