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
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ test-coverage:
@set -o pipefail && (cd node && go test -count=1 -v -timeout 5m -race -cover ./...) 2>&1 | tee coverage.txt
@set -o pipefail && (cd sdk && go test -count=1 -v -timeout 5m -race -cover ./...) 2>&1 | tee -a coverage.txt

.PHONY: test-fast
## Run fast tests for node and sdk, skipping tests gated by testing.Short() and fuzz smoke tests
test-fast:
@echo "Running fast tests for node and sdk..."
@cd node && go test -short ./...
@cd sdk && go test -short ./...

.PHONY: check-coverage
## Check coverage against baseline (run tests first)
check-coverage: build-coverage-check test-coverage
Expand Down
8 changes: 6 additions & 2 deletions node/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
.PHONY: lint
lint:
lint:
golangci-lint run -c ../.golangci.yml ./...

.PHONY: test
test:
go test -v ./...
timeout 10s go test -fuzz=FuzzMessagePublicationUnmarshalBinary -fuzztime=5s ./pkg/common || true
timeout 5s go test -fuzz=FuzzMessagePublicationUnmarshalBinary -fuzztime=3s ./pkg/common || true

.PHONY: test-fast
test-fast:
go test -short ./...

.PHONY: test-coverage
test-coverage:
Expand Down
14 changes: 14 additions & 0 deletions node/pkg/db/accountant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
)

func TestAcctPendingTransferMsgID(t *testing.T) {
t.Parallel()

tokenBridgeAddr, err := vaa.StringToAddress("0x0290fb167208af455bb137780163b7b7a9a10c16")
require.NoError(t, err)

Expand All @@ -42,6 +44,8 @@ func TestAcctPendingTransferMsgID(t *testing.T) {
}

func TestAcctIsPendingTransfer(t *testing.T) {
t.Parallel()

assert.Equal(t, true, acctIsPendingTransfer([]byte("ACCT:PXFER3:"+"2/0000000000000000000000000290fb167208af455bb137780163b7b7a9a10c16/789101112131415")))
assert.Equal(t, false, acctIsPendingTransfer([]byte("ACCT:PXFER3:")))
assert.Equal(t, false, acctIsPendingTransfer([]byte("ACCT:PXFER3:1")))
Expand All @@ -56,6 +60,8 @@ func TestAcctIsPendingTransfer(t *testing.T) {
}

func TestAcctStoreAndDeletePendingTransfers(t *testing.T) {
t.Parallel()

dbPath := t.TempDir()
db := OpenDb(zap.NewNop(), &dbPath)
defer db.Close()
Expand Down Expand Up @@ -119,6 +125,8 @@ func TestAcctStoreAndDeletePendingTransfers(t *testing.T) {
}

func TestAcctGetEmptyData(t *testing.T) {
t.Parallel()

logger := zap.NewNop()
dbPath := t.TempDir()
db := OpenDb(logger, &dbPath)
Expand All @@ -130,6 +138,8 @@ func TestAcctGetEmptyData(t *testing.T) {
}

func TestAcctGetData(t *testing.T) {
t.Parallel()

logger := zap.NewNop()
dbPath := t.TempDir()
db := OpenDb(logger, &dbPath)
Expand Down Expand Up @@ -194,6 +204,8 @@ func TestAcctGetData(t *testing.T) {
}

func TestAcctLoadingWhereOldPendingGetsUpdated(t *testing.T) {
t.Parallel()

dbPath := t.TempDir()
db := OpenDb(zap.NewNop(), &dbPath)
defer db.Close()
Expand Down Expand Up @@ -325,6 +337,8 @@ func (msg *OldMessagePublication) MessageIDString() string {
}

func TestUnmarshalOldJSON(t *testing.T) {
t.Parallel()

jsn := `
{
"TxID": "SGVsbG8=",
Expand Down
24 changes: 24 additions & 0 deletions node/pkg/db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func getVAAWithSeqNum(seqNum uint64) vaa.VAA {

// Testing the expected default behavior of a CreateGovernanceVAA
func TestVaaIDFromString(t *testing.T) {
t.Parallel()

vaaIdString := "1/0000000000000000000000000000000000000000000000000000000000000004/1"
vaaID, _ := VaaIDFromString(vaaIdString)
expectAddr := vaa.Address{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4}
Expand All @@ -57,6 +59,8 @@ func TestVaaIDFromString(t *testing.T) {
}

func TestVaaIDFromVAA(t *testing.T) {
t.Parallel()

testVaa := getVAA()
vaaID := VaaIDFromVAA(&testVaa)
expectAddr := vaa.Address{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4}
Expand All @@ -67,6 +71,8 @@ func TestVaaIDFromVAA(t *testing.T) {
}

func TestBytes(t *testing.T) {
t.Parallel()

vaaIdString := "1/0000000000000000000000000000000000000000000000000000000000000004/1"
vaaID, _ := VaaIDFromString(vaaIdString)
expected := []byte{0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x2f, 0x31, 0x2f, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x2f, 0x31}
Expand All @@ -75,6 +81,8 @@ func TestBytes(t *testing.T) {
}

func TestEmitterPrefixBytesWithChainIDAndAddress(t *testing.T) {
t.Parallel()

vaaIdString := "1/0000000000000000000000000000000000000000000000000000000000000004/1"
vaaID, _ := VaaIDFromString(vaaIdString)
expected := []byte{0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x2f, 0x31, 0x2f, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34}
Expand All @@ -83,11 +91,15 @@ func TestEmitterPrefixBytesWithChainIDAndAddress(t *testing.T) {
}

func TestEmitterPrefixBytesWithOnlyChainID(t *testing.T) {
t.Parallel()

vaaID := VAAID{EmitterChain: vaa.ChainID(26)}
assert.Equal(t, []byte("signed/26"), vaaID.EmitterPrefixBytes())
}

func TestStoreSignedVAAUnsigned(t *testing.T) {
t.Parallel()

dbPath := t.TempDir()
db := OpenDb(zap.NewNop(), &dbPath)
defer db.Close()
Expand All @@ -100,6 +112,8 @@ func TestStoreSignedVAAUnsigned(t *testing.T) {
}

func TestStoreSignedVAASigned(t *testing.T) {
t.Parallel()

dbPath := t.TempDir()
db := OpenDb(zap.NewNop(), &dbPath)
defer db.Close()
Expand All @@ -115,6 +129,12 @@ func TestStoreSignedVAASigned(t *testing.T) {
}

func TestStoreSignedVAABatch(t *testing.T) {
if testing.Short() {
t.Skip("skipping large signed VAA batch stress test in short mode")
}

t.Parallel()

dbPath := t.TempDir()
db := OpenDb(zap.NewNop(), &dbPath)
defer db.Close()
Expand Down Expand Up @@ -174,6 +194,8 @@ func TestStoreSignedVAABatch(t *testing.T) {
}

func TestGetSignedVAABytes(t *testing.T) {
t.Parallel()

dbPath := t.TempDir()
db := OpenDb(zap.NewNop(), &dbPath)
defer db.Close()
Expand Down Expand Up @@ -201,6 +223,8 @@ func TestGetSignedVAABytes(t *testing.T) {
}

func TestFindEmitterSequenceGap(t *testing.T) {
t.Parallel()

dbPath := t.TempDir()
db := OpenDb(zap.NewNop(), &dbPath)
defer db.Close()
Expand Down
48 changes: 48 additions & 0 deletions node/pkg/db/governor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func (d *Database) rowExistsInDB(key []byte) error {
}

func TestSerializeAndDeserializeOfTransfer(t *testing.T) {
t.Parallel()

tokenAddr, err := vaa.StringToAddress("0x707f9118e33a9b8998bea41dd0d46f38bb963fc8")
require.NoError(t, err)

Expand Down Expand Up @@ -58,6 +60,8 @@ func TestSerializeAndDeserializeOfTransfer(t *testing.T) {
}

func TestPendingMsgIDV5(t *testing.T) {
t.Parallel()

ethereumTokenBridgeAddr, err := vaa.StringToAddress("0x0290fb167208af455bb137780163b7b7a9a10c16")
require.NoError(t, err)

Expand All @@ -76,6 +80,8 @@ func TestPendingMsgIDV5(t *testing.T) {
}

func TestTransferMsgIDV5(t *testing.T) {
t.Parallel()

tokenAddr, err := vaa.StringToAddress("0x707f9118e33a9b8998bea41dd0d46f38bb963fc8")
require.NoError(t, err)

Expand Down Expand Up @@ -103,6 +109,8 @@ func TestTransferMsgIDV5(t *testing.T) {

// TestTransferMsgIDV4 tests the old transfer format prefix (now superseded by V5).
func TestTransferMsgIDV4(t *testing.T) {
t.Parallel()

tokenAddr, err := vaa.StringToAddress("0x707f9118e33a9b8998bea41dd0d46f38bb963fc8")
require.NoError(t, err)

Expand Down Expand Up @@ -131,6 +139,8 @@ func TestTransferMsgIDV4(t *testing.T) {
// TestIsTransferV5 tests the IsTransfer function for the current transfer format.
// The V5 suffix matches the "GOV:XFER5:" prefix used by the current transfer implementation.
func TestIsTransferV5(t *testing.T) {
t.Parallel()

tests := []struct {
name string
input []byte
Expand Down Expand Up @@ -189,7 +199,10 @@ func TestIsTransferV5(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

result := IsTransfer(tt.input)
assert.Equal(t, tt.expected, result)
})
Expand All @@ -199,6 +212,8 @@ func TestIsTransferV5(t *testing.T) {
// TestIsTransferV4 tests the isOldTransfer function for the legacy transfer format.
// The V4 suffix matches the "GOV:XFER4:" prefix used by the old transfer implementation.
func TestIsTransferV4(t *testing.T) {
t.Parallel()

tests := []struct {
name string
input []byte
Expand Down Expand Up @@ -252,7 +267,10 @@ func TestIsTransferV4(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

result := isOldTransfer(tt.input)
assert.Equal(t, tt.expected, result)
})
Expand All @@ -262,6 +280,8 @@ func TestIsTransferV4(t *testing.T) {
// TestIsPendingMsgV5 tests the IsPendingMsg function for the current pending message format.
// The V5 suffix matches the "GOV:PENDING5:" prefix used by the current pending message implementation.
func TestIsPendingMsgV5(t *testing.T) {
t.Parallel()

tests := []struct {
name string
input []byte
Expand Down Expand Up @@ -320,7 +340,10 @@ func TestIsPendingMsgV5(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

result := IsPendingMsg(tt.input)
assert.Equal(t, tt.expected, result)
})
Expand All @@ -330,6 +353,8 @@ func TestIsPendingMsgV5(t *testing.T) {
// TestIsPendingMsgV4 tests the isOldPendingMsg function for the legacy pending message format.
// The V4 suffix matches the "GOV:PENDING4:" prefix used by the legacy pending message implementation.
func TestIsPendingMsgV4(t *testing.T) {
t.Parallel()

tests := []struct {
name string
input []byte
Expand Down Expand Up @@ -383,14 +408,19 @@ func TestIsPendingMsgV4(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

result := isOldPendingMsg(tt.input)
assert.Equal(t, tt.expected, result)
})
}
}

func TestGetChainGovernorData(t *testing.T) {
t.Parallel()

dbPath := t.TempDir()
db := OpenDb(zap.NewNop(), &dbPath)
defer db.Close()
Expand All @@ -405,6 +435,8 @@ func TestGetChainGovernorData(t *testing.T) {
}

func TestStoreTransfer(t *testing.T) {
t.Parallel()

dbPath := t.TempDir()
db := OpenDb(zap.NewNop(), &dbPath)
defer db.Close()
Expand Down Expand Up @@ -436,6 +468,8 @@ func TestStoreTransfer(t *testing.T) {
}

func TestDeleteTransfer(t *testing.T) {
t.Parallel()

dbPath := t.TempDir()
db := OpenDb(zap.NewNop(), &dbPath)
defer db.Close()
Expand Down Expand Up @@ -476,6 +510,8 @@ func TestDeleteTransfer(t *testing.T) {
}

func TestStorePendingMsg(t *testing.T) {
t.Parallel()

dbPath := t.TempDir()
db := OpenDb(zap.NewNop(), &dbPath)
defer db.Close()
Expand All @@ -501,6 +537,8 @@ func TestStorePendingMsg(t *testing.T) {
}

func TestDeletePendingMsg(t *testing.T) {
t.Parallel()

dbPath := t.TempDir()
db := OpenDb(zap.NewNop(), &dbPath)
defer db.Close()
Expand Down Expand Up @@ -535,6 +573,8 @@ func TestDeletePendingMsg(t *testing.T) {
}

func TestSerializeAndDeserializeOfPendingTransfer(t *testing.T) {
t.Parallel()

tokenBridgeAddr, err := vaa.StringToAddress("0x0290fb167208af455bb137780163b7b7a9a10c16")
require.NoError(t, err)

Expand Down Expand Up @@ -570,6 +610,8 @@ func TestSerializeAndDeserializeOfPendingTransfer(t *testing.T) {
}

func TestStoreAndReloadTransfersAndPendingMessages(t *testing.T) {
t.Parallel()

dbPath := t.TempDir()
db := OpenDb(zap.NewNop(), &dbPath)
defer db.Close()
Expand Down Expand Up @@ -664,6 +706,8 @@ func TestStoreAndReloadTransfersAndPendingMessages(t *testing.T) {
}

func TestMarshalUnmarshalNoMsgIdOrHash(t *testing.T) {
t.Parallel()

tokenAddr, err := vaa.StringToAddress("0x707f9118e33a9b8998bea41dd0d46f38bb963fc8")
require.NoError(t, err)

Expand Down Expand Up @@ -696,6 +740,8 @@ func TestMarshalUnmarshalNoMsgIdOrHash(t *testing.T) {
// Note that Transfer.Marshal can't fail, so there are no negative tests for that.

func TestUnmarshalTransferFailures(t *testing.T) {
t.Parallel()

tokenAddr, err := vaa.StringToAddress("0x707f9118e33a9b8998bea41dd0d46f38bb963fc8")
require.NoError(t, err)

Expand Down Expand Up @@ -778,6 +824,8 @@ func TestUnmarshalTransferFailures(t *testing.T) {
// Note that PendingTransfer.Marshal can't fail, so there are no negative tests for that.

func TestUnmarshalPendingTransferFailures(t *testing.T) {
t.Parallel()

tokenBridgeAddr, err := vaa.StringToAddress("0x0290fb167208af455bb137780163b7b7a9a10c16")
require.NoError(t, err)

Expand Down
Loading
Loading