Skip to content

Commit

Permalink
Add CLI tests for exits
Browse files Browse the repository at this point in the history
  • Loading branch information
KaloyanTanev committed Oct 23, 2024
1 parent fe7378d commit b0a1ed2
Show file tree
Hide file tree
Showing 4 changed files with 290 additions and 0 deletions.
89 changes: 89 additions & 0 deletions cmd/exit_broadcast_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,92 @@ func Test_runBcastFullExitCmd_Config(t *testing.T) {
})
}
}

func TestExitBroadcastCLI(t *testing.T) {
tests := []struct {
name string
expectedErr string

flags []string
}{
{
name: "check flags",
expectedErr: "load identity key: read private key from disk: open test: no such file or directory",
flags: []string{
"--publish-address=test",
"--private-key-file=test",
"--lock-file=test",
"--validator-keys-dir=test",
"--exit-epoch=1",
"--validator-public-key=test", // single exit
"--beacon-node-endpoints=test1,test2",
"--exit-from-file=test", // single exit
"--beacon-node-timeout=1ms",
"--publish-timeout=1ms",
"--all=false", // single exit
"--testnet-name=test",
"--testnet-fork-version=test",
"--testnet-chain-id=1",
"--testnet-genesis-timestamp=1",
"--testnet-capella-hard-fork=test",
},
},
{
name: "check flags all",
expectedErr: "load identity key: read private key from disk: open test: no such file or directory",
flags: []string{
"--publish-address=test",
"--private-key-file=test",
"--lock-file=test",
"--validator-keys-dir=test", // exit all
"--exit-epoch=1",
"--beacon-node-endpoints=test1,test2",
"--exit-from-dir=test",
"--beacon-node-timeout=1ms",
"--publish-timeout=1ms",
"--all", // exit all
"--testnet-name=test",
"--testnet-fork-version=test",
"--testnet-chain-id=1",
"--testnet-genesis-timestamp=1",
"--testnet-capella-hard-fork=test",
},
},
{
name: "check flags all",
expectedErr: "load identity key: read private key from disk: open test: no such file or directory",
flags: []string{
"--publish-address=test",
"--private-key-file=test",
"--lock-file=test",
"--validator-keys-dir=test", // exit all
"--exit-epoch=1",
"--beacon-node-endpoints=test1,test2",
"--exit-from-dir=test",
"--beacon-node-timeout=1ms",
"--publish-timeout=1ms",
"--all", // exit all
"--testnet-name=test",
"--testnet-fork-version=test",
"--testnet-chain-id=1",
"--testnet-genesis-timestamp=1",
"--testnet-capella-hard-fork=test",
},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
cmd := newExitCmd(newBcastFullExitCmd(runBcastFullExit))
cmd.SetArgs(append([]string{"broadcast"}, test.flags...))

err := cmd.Execute()
if test.expectedErr != "" {
require.Error(t, err)
require.ErrorContains(t, err, test.expectedErr)
} else {
require.NoError(t, err)
}
})
}
}
67 changes: 67 additions & 0 deletions cmd/exit_fetch_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,70 @@ func Test_runFetchExitBadOutDir(t *testing.T) {

require.ErrorContains(t, runFetchExit(context.Background(), config), "permission denied")
}

func TestExitFetchCLI(t *testing.T) {
tests := []struct {
name string
expectedErr string

publishAddress string
privateKeyPath string
lockFilePath string
validatorPubkey string
all string
fetchedExitPath string
publishTimeout string
testnetName string
testnetForkVersion string
testnetChainID string
testnetGenesisTimestamp string
testnetCapellaHardFork string
}{
{
name: "check flags",
expectedErr: "store exit path: stat 1: no such file or directory",

publishAddress: "--publish-address=test",
privateKeyPath: "--private-key-file=test",
lockFilePath: "--lock-file=test",
validatorPubkey: "--validator-public-key=test",
fetchedExitPath: "--fetched-exit-path=1",
publishTimeout: "--publish-timeout=1ms",
all: "--all=false",
testnetName: "--testnet-name=test",
testnetForkVersion: "--testnet-fork-version=test",
testnetChainID: "--testnet-chain-id=1",
testnetGenesisTimestamp: "--testnet-genesis-timestamp=1",
testnetCapellaHardFork: "--testnet-capella-hard-fork=test",
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
cmd := newExitCmd(newFetchExitCmd(runFetchExit))
cmd.SetArgs([]string{
"fetch",
test.publishAddress,
test.privateKeyPath,
test.lockFilePath,
test.validatorPubkey,
test.fetchedExitPath,
test.publishTimeout,
test.all,
test.testnetName,
test.testnetForkVersion,
test.testnetChainID,
test.testnetGenesisTimestamp,
test.testnetCapellaHardFork,
})

err := cmd.Execute()
if test.expectedErr != "" {
require.Error(t, err)
require.ErrorContains(t, err, test.expectedErr)
} else {
require.NoError(t, err)
}
})
}
}
55 changes: 55 additions & 0 deletions cmd/exit_list_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,58 @@ func Test_listActiveVals(t *testing.T) {
require.Len(t, vals, len(lock.Validators)/2)
})
}

func TestExitListCLI(t *testing.T) {
tests := []struct {
name string
expectedErr string

lockFilePath string
beaconNodeEndpoints string
beaconNodeTimeout string
testnetName string
testnetForkVersion string
testnetChainID string
testnetGenesisTimestamp string
testnetCapellaHardFork string
}{
{
name: "check flags",
expectedErr: "load cluster lock: load cluster manifest from disk: load dag from disk: no file found",

lockFilePath: "--lock-file=test",
beaconNodeEndpoints: "--beacon-node-endpoints=test1,test2",
beaconNodeTimeout: "--beacon-node-timeout=1ms",
testnetName: "--testnet-name=test",
testnetForkVersion: "--testnet-fork-version=test",
testnetChainID: "--testnet-chain-id=1",
testnetGenesisTimestamp: "--testnet-genesis-timestamp=1",
testnetCapellaHardFork: "--testnet-capella-hard-fork=test",
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
cmd := newExitCmd(newListActiveValidatorsCmd(runListActiveValidatorsCmd))
cmd.SetArgs([]string{
"active-validator-list",
test.lockFilePath,
test.beaconNodeEndpoints,
test.beaconNodeTimeout,
test.testnetName,
test.testnetForkVersion,
test.testnetChainID,
test.testnetGenesisTimestamp,
test.testnetCapellaHardFork,
})

err := cmd.Execute()
if test.expectedErr != "" {
require.Error(t, err)
require.ErrorContains(t, err, test.expectedErr)
} else {
require.NoError(t, err)
}
})
}
}
79 changes: 79 additions & 0 deletions cmd/exit_sign_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,82 @@ func Test_runSubmitPartialExit_Config(t *testing.T) {
})
}
}

func TestExitSignCLI(t *testing.T) {
tests := []struct {
name string
expectedErr string

publishAddress string
privateKeyPath string
lockFilePath string
validatorKeysDir string
exitEpoch string
validatorPubkey string
validatorIndex string
beaconNodeEndpoints string
beaconNodeTimeout string
publishTimeout string
all string
testnetName string
testnetForkVersion string
testnetChainID string
testnetGenesisTimestamp string
testnetCapellaHardFork string
}{
{
name: "check flags",
expectedErr: "load identity key: read private key from disk: open test: no such file or directory",

publishAddress: "--publish-address=test",
privateKeyPath: "--private-key-file=test",
lockFilePath: "--lock-file=test",
validatorKeysDir: "--validator-keys-dir=test",
exitEpoch: "--exit-epoch=1",
validatorPubkey: "--validator-public-key=test",
validatorIndex: "--validator-index=1",
beaconNodeEndpoints: "--beacon-node-endpoints=test1,test2",
beaconNodeTimeout: "--beacon-node-timeout=1ms",
publishTimeout: "--publish-timeout=1ms",
all: "--all=false",
testnetName: "--testnet-name=test",
testnetForkVersion: "--testnet-fork-version=test",
testnetChainID: "--testnet-chain-id=1",
testnetGenesisTimestamp: "--testnet-genesis-timestamp=1",
testnetCapellaHardFork: "--testnet-capella-hard-fork=test",
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
cmd := newExitCmd(newSignPartialExitCmd(runSignPartialExit))
cmd.SetArgs([]string{
"sign",
test.publishAddress,
test.privateKeyPath,
test.lockFilePath,
test.validatorKeysDir,
test.exitEpoch,
test.validatorPubkey,
test.validatorIndex,
test.beaconNodeEndpoints,
test.beaconNodeTimeout,
test.publishTimeout,
test.all,
test.testnetName,
test.testnetForkVersion,
test.testnetChainID,
test.testnetGenesisTimestamp,
test.testnetCapellaHardFork,
})

err := cmd.Execute()
if test.expectedErr != "" {
require.Error(t, err)
require.ErrorContains(t, err, test.expectedErr)
} else {
require.NoError(t, err)
}
})
}
}

0 comments on commit b0a1ed2

Please sign in to comment.