Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 73 additions & 34 deletions actions/action.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions actions/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
func TestActionProtoRoundTrip(t *testing.T) {
want := &Action{
BlockHeight: 42,
FeePayer: []byte("alice"),
XCoordinate: append(make([]byte, 31), 1),
IsOdd: true,
ActionType: ActionType_DEPOSIT,
Amount: 99,
}
Expand All @@ -29,7 +30,8 @@ func TestDbRecordProtoRoundTrip(t *testing.T) {
Actions: []*Action{
{
BlockHeight: 7,
FeePayer: []byte("alice"),
XCoordinate: append(make([]byte, 31), 1),
IsOdd: true,
ActionType: ActionType_WITHDRAW,
Amount: 11,
},
Expand Down
4 changes: 2 additions & 2 deletions apperrors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ var (
ErrInvalidAmount = errors.New("invalid action amount")
// ErrInvalidActionData reports that an action payload is missing required fields.
ErrInvalidActionData = errors.New("invalid action data")
// ErrMissingFeePayer reports that an action payload is missing the fee payer account.
ErrMissingFeePayer = errors.New("missing fee payer")
// ErrEmptyXCoordinate reports that an action payload is missing the x-coordinate of account's pubkey.
ErrEmptyXCoordinate = errors.New("empty x coordinate")
)

var (
Expand Down
31 changes: 31 additions & 0 deletions cmd/archive-wrapper/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
)

func TestRunCommandRejectsMissingPostgresBeforeDatabaseCreation(t *testing.T) {
clearCommandEnvironment(t)
root := t.TempDir()
dbPath := filepath.Join(root, "wrapper-db")
controlSocketPath := filepath.Join(root, "control.sock")
Expand All @@ -39,6 +40,7 @@ func TestRunCommandRejectsMissingPostgresBeforeDatabaseCreation(t *testing.T) {
}

func TestRemovedLifecycleCommandsAreRejected(t *testing.T) {
clearCommandEnvironment(t)
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
for _, command := range []string{"start", "proceed"} {
t.Run(command, func(t *testing.T) {
Expand All @@ -49,6 +51,7 @@ func TestRemovedLifecycleCommandsAreRejected(t *testing.T) {
}

func TestCommandsRejectUnexpectedArguments(t *testing.T) {
clearCommandEnvironment(t)
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
tests := []struct {
name string
Expand All @@ -67,6 +70,7 @@ func TestCommandsRejectUnexpectedArguments(t *testing.T) {
}

func TestStopRejectsLegacySocketPathFlag(t *testing.T) {
clearCommandEnvironment(t)
err := run(
[]string{"stop", "--socket-path", "/tmp/wrapper.sock"},
context.Background(),
Expand All @@ -77,6 +81,7 @@ func TestStopRejectsLegacySocketPathFlag(t *testing.T) {
}

func TestResolveConfigPathPrecedence(t *testing.T) {
clearCommandEnvironment(t)
tests := []struct {
name string
args []string
Expand Down Expand Up @@ -114,6 +119,7 @@ func TestResolveConfigPathPrecedence(t *testing.T) {
}

func TestResolveStopSocketPathPrecedence(t *testing.T) {
clearCommandEnvironment(t)
configPath := writeStopConfig(t, "/tmp/config.sock")

t.Run("cli_over_environment_and_config", func(t *testing.T) {
Expand Down Expand Up @@ -216,3 +222,28 @@ func unsetEnvironment(t *testing.T, key string) {
func stringPointer(value string) *string {
return &value
}

func clearCommandEnvironment(t *testing.T) {
t.Helper()
for _, key := range []string{
"ARCHIVE_WRAPPER_CONFIG",
"ARCHIVE_WRAPPER_CHAIN_HOME",
"ARCHIVE_WRAPPER_DB_PATH",
"ARCHIVE_WRAPPER_GRPC_LISTEN_ADDRESS",
"ARCHIVE_WRAPPER_GRPC_TRANSPORT_MODE",
"ARCHIVE_WRAPPER_CONTROL_SOCKET_PATH",
"ARCHIVE_WRAPPER_HEALTHCHECK_ADDRESS",
"ARCHIVE_WRAPPER_LOG_PATH",
"POSTGRES_URI",
} {
oldValue, wasSet := os.LookupEnv(key)
require.NoError(t, os.Unsetenv(key))
t.Cleanup(func() {
if wasSet {
require.NoError(t, os.Setenv(key, oldValue))
return
}
require.NoError(t, os.Unsetenv(key))
})
}
}
20 changes: 14 additions & 6 deletions cmd/archive-wrapper/control_socket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ import (

func TestCloseControlSocketListenerPreservesReplacementSocket(t *testing.T) {
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
socketPath := filepath.Join("/tmp", fmt.Sprintf("archive-wrapper-%d.sock", time.Now().UnixNano()))
t.Cleanup(func() {
_ = os.Remove(socketPath)
})
socketPath := testSocketPath(t, "replacement")

listener, err := net.Listen(network, socketPath)
require.NoError(t, err)
Expand Down Expand Up @@ -49,7 +46,7 @@ func TestCloseControlSocketListenerPreservesReplacementSocket(t *testing.T) {

func TestControlServerCloseIsIdempotentAndRemovesSocket(t *testing.T) {
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
socketPath := filepath.Join(t.TempDir(), "control.sock")
socketPath := testSocketPath(t, "close")
server, err := listenControlSocket(socketPath, func() {}, logger)
require.NoError(t, err)

Expand All @@ -66,7 +63,7 @@ func TestControlServerCloseIsIdempotentAndRemovesSocket(t *testing.T) {

func TestControlServerStopCommandCancelsRuntime(t *testing.T) {
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
socketPath := filepath.Join(t.TempDir(), "control.sock")
socketPath := testSocketPath(t, "stop")
canceled := make(chan struct{})
server, err := listenControlSocket(socketPath, func() { close(canceled) }, logger)
require.NoError(t, err)
Expand Down Expand Up @@ -103,3 +100,14 @@ func (l *replacementListener) Close() error {
l.replacement = replacement
return nil
}

func testSocketPath(t *testing.T, prefix string) string {
t.Helper()

socketPath := filepath.Join("/tmp", fmt.Sprintf("archive-wrapper-%s-%d.sock", prefix, time.Now().UnixNano()))
t.Cleanup(func() {
_ = os.Remove(socketPath)
})

return socketPath
}
8 changes: 8 additions & 0 deletions cmd/archive-wrapper/healthcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
)

func TestHealthDialAddress(t *testing.T) {
clearCommandEnvironment(t)
tests := []struct {
name string
address string
Expand Down Expand Up @@ -46,6 +47,7 @@ func TestHealthDialAddress(t *testing.T) {
}

func TestResolveHealthcheckAddressPrecedence(t *testing.T) {
clearCommandEnvironment(t)
configPath := writeHealthcheckConfig(t, "127.0.0.1:9001")
lookup := mapLookup(map[string]string{
"ARCHIVE_WRAPPER_CONFIG": configPath,
Expand All @@ -66,6 +68,7 @@ func TestResolveHealthcheckAddressPrecedence(t *testing.T) {
}

func TestResolveHealthcheckAddressUsesRuntimeEnvironment(t *testing.T) {
clearCommandEnvironment(t)
configPath := writeHealthcheckConfig(t, "127.0.0.1:9001")
t.Setenv("ARCHIVE_WRAPPER_GRPC_LISTEN_ADDRESS", "0.0.0.0:9004")
t.Setenv("ARCHIVE_WRAPPER_GRPC_TRANSPORT_MODE", "trusted-network")
Expand All @@ -76,6 +79,7 @@ func TestResolveHealthcheckAddressUsesRuntimeEnvironment(t *testing.T) {
}

func TestResolveHealthcheckAddressRejectsEmptyExplicitValues(t *testing.T) {
clearCommandEnvironment(t)
_, err := resolveHealthcheckAddress("", true, "unused", true, mapLookup(nil))
require.ErrorIs(t, err, apperrors.ErrGRPCAddressRequired)

Expand All @@ -89,6 +93,7 @@ func TestResolveHealthcheckAddressRejectsEmptyExplicitValues(t *testing.T) {
}

func TestCheckQueryHealth(t *testing.T) {
clearCommandEnvironment(t)
tests := []struct {
name string
status grpcHealthV1.HealthCheckResponse_ServingStatus
Expand Down Expand Up @@ -116,12 +121,14 @@ func TestCheckQueryHealth(t *testing.T) {
}

func TestCheckQueryHealthFailsForUnavailableTarget(t *testing.T) {
clearCommandEnvironment(t)
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Millisecond)
defer cancel()
require.Error(t, checkQueryHealth(ctx, "127.0.0.1:1"))
}

func TestRunMainHealthcheckDoesNotInitializeRuntimeLogger(t *testing.T) {
clearCommandEnvironment(t)
logPath := filepath.Join(t.TempDir(), "healthcheck.log")
t.Setenv("ARCHIVE_WRAPPER_LOG_PATH", logPath)
var stderr bytes.Buffer
Expand All @@ -137,6 +144,7 @@ func TestRunMainHealthcheckDoesNotInitializeRuntimeLogger(t *testing.T) {
}

func TestRunHealthcheckRejectsNonPositiveTimeout(t *testing.T) {
clearCommandEnvironment(t)
err := runHealthcheckCommand([]string{"--address", "127.0.0.1:9095", "--timeout", "0s"}, mapLookup(nil))
require.ErrorContains(t, err, "greater than zero")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/archive-wrapper/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestRunRuntimeStopsCleanlyOnExternalCancellation(t *testing.T) {
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
root := t.TempDir()
dbPath := filepath.Join(root, "db")
controlSocketPath := filepath.Join(root, "control.sock")
controlSocketPath := testSocketPath(t, "runtime")
inputs := testRuntimeInputs(dbPath, controlSocketPath)
inputs.Config.GRPCListenAddress = reserveLoopbackAddress(t)
inputs.BridgeParams.ContractAddress = testBridgeContractAddress
Expand Down
Loading
Loading