-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add thor tests * Fix linter issue * tweak tests --------- Co-authored-by: tony <[email protected]>
- Loading branch information
1 parent
6588f04
commit 3ad407a
Showing
4 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package thor | ||
|
||
import "testing" | ||
|
||
func TestBlocklistInitialization(t *testing.T) { | ||
knownBlocked := []string{ | ||
"0x4427be8010dd870395975a8fbaa7afa9439b5332", | ||
"0xa99bd128a454728b509ab0e41499a6d1ea0d3416", | ||
} | ||
|
||
for _, addrStr := range knownBlocked { | ||
addr := MustParseAddress(addrStr) | ||
if !IsOriginBlocked(addr) { | ||
t.Errorf("Address %s is expected to be blocked, but IsOriginBlocked returned false", addrStr) | ||
} | ||
} | ||
|
||
// Address known not to be in the blocklist | ||
knownUnblocked := "0x000000000000000000000000000000000000dead" | ||
addr := MustParseAddress(knownUnblocked) | ||
if IsOriginBlocked(addr) { | ||
t.Errorf("Address %s is expected to be unblocked, but IsOriginBlocked returned true", knownUnblocked) | ||
} | ||
} | ||
|
||
func TestMockBlocklist(t *testing.T) { | ||
// Setup mock blocklist with a new set of addresses | ||
mockAddresses := []string{ | ||
"0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", | ||
"0xfeedbeeffeedbeeffeedbeeffeedbeeffeedbeef", | ||
} | ||
MockBlocklist(mockAddresses) | ||
|
||
// Test to ensure the mock blocklist is now in effect | ||
tests := []struct { | ||
address string | ||
blocked bool | ||
}{ | ||
{mockAddresses[0], true}, | ||
{mockAddresses[1], true}, | ||
// An address known to be in the original blocklist, expecting it to be unblocked after mocking | ||
{"0x4427be8010dd870395975a8fbaa7afa9439b5332", false}, | ||
} | ||
|
||
for _, tt := range tests { | ||
addr := MustParseAddress(tt.address) | ||
if IsOriginBlocked(addr) != tt.blocked { | ||
t.Errorf("MockBlocklist failed for %v: expected blocked=%v, got blocked=%v", tt.address, tt.blocked, !tt.blocked) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package thor | ||
|
||
import ( | ||
"math" | ||
"testing" | ||
) | ||
|
||
// TestForkConfigString verifies that the String method returns expected values. | ||
func TestForkConfigString(t *testing.T) { | ||
fc := ForkConfig{ | ||
VIP191: 1, | ||
ETH_CONST: math.MaxUint32, | ||
BLOCKLIST: 2, | ||
ETH_IST: math.MaxUint32, | ||
VIP214: math.MaxUint32, | ||
FINALITY: math.MaxUint32, | ||
} | ||
|
||
expectedStr := "VIP191: #1, BLOCKLIST: #2" | ||
if fc.String() != expectedStr { | ||
t.Errorf("ForkConfig.String() = %v, want %v", fc.String(), expectedStr) | ||
} | ||
} | ||
|
||
// TestNoFork verifies the NoFork variable is correctly set up. | ||
func TestNoFork(t *testing.T) { | ||
if NoFork.VIP191 != math.MaxUint32 || NoFork.BLOCKLIST != math.MaxUint32 { | ||
t.Errorf("NoFork does not correctly represent a configuration with no forks") | ||
} | ||
} | ||
|
||
// TestGetForkConfig checks retrieval of fork configurations for known genesis IDs. | ||
func TestGetForkConfig(t *testing.T) { | ||
// You'll need to adjust these based on the actual genesis IDs and expected configurations | ||
mainnetID := MustParseBytes32("0x00000000851caf3cfdb6e899cf5958bfb1ac3413d346d43539627e6be7ec1b4a") | ||
testnetID := MustParseBytes32("0x000000000b2bce3c70bc649a02749e8687721b09ed2e15997f466536b20bb127") | ||
unknownID := MustParseBytes32("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") | ||
|
||
tests := []struct { | ||
id Bytes32 | ||
expectFound bool | ||
}{ | ||
{mainnetID, true}, | ||
{testnetID, true}, | ||
{unknownID, false}, // Expect no config for unknown ID | ||
} | ||
|
||
for _, tt := range tests { | ||
config := GetForkConfig(tt.id) | ||
if (config != ForkConfig{}) != tt.expectFound { | ||
t.Errorf("GetForkConfig(%v) found = %v, want %v", tt.id, !tt.expectFound, tt.expectFound) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package thor | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
// TestLoadCorrectReceiptsRootsForKeyValue tests a specific key/value pair in the map returned by LoadCorrectReceiptsRoots | ||
func TestLoadCorrectReceiptsRootsForKeyValue(t *testing.T) { | ||
// Define the key/value pair you expect to find | ||
expectedKey := "0x000c2c63d845188f8390de84d1364b59cd2890f276452762f9ab0761ecc93069" | ||
expectedValue := "0xe467857991d0e04da9b2e0365110b49f198febf9d3fa8413c536527f857bd246" | ||
|
||
// Load the map | ||
actualMap := LoadCorrectReceiptsRoots() | ||
|
||
// Check if the key exists | ||
actualValue, exists := actualMap[expectedKey] | ||
if !exists { | ||
t.Fatalf("Expected key %s not found in the map", expectedKey) | ||
} | ||
|
||
// Check if the value matches | ||
if expectedValue != actualValue { | ||
t.Errorf("For key %s, expected value %s, got %s", expectedKey, expectedValue, actualValue) | ||
} | ||
} |