Skip to content

Commit

Permalink
test: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ziscky committed Jan 22, 2025
1 parent 731a4bd commit 46b3650
Show file tree
Hide file tree
Showing 24 changed files with 176 additions and 140 deletions.
7 changes: 5 additions & 2 deletions actors/account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ var expectedData []byte
var expected map[string]any
var lib *rosettaFilecoinLib.RosettaConstructionFilecoin

var network string

func TestMain(m *testing.M) {
var err error
network = "mainnet"
lib, err = tools.GetLib(tools.NodeUrl)
if err != nil {
panic(err)
Expand All @@ -35,7 +38,7 @@ func TestMain(m *testing.M) {
}

func TestAuthenticateMessage(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("AuthenticateMessage", expected)
tests, err := tools.LoadTestData[map[string]any](network, "AuthenticateMessage", expected)
require.NoError(t, err)
for _, tt := range tests {
t.Run(tt.Name, func(t *testing.T) {
Expand All @@ -55,7 +58,7 @@ func TestAuthenticateMessage(t *testing.T) {
}

func TestPubkeyAddress(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("PubkeyAddress", expected)
tests, err := tools.LoadTestData[map[string]any](network, "PubkeyAddress", expected)
require.NoError(t, err)

for _, tt := range tests {
Expand Down
4 changes: 3 additions & 1 deletion actors/cron/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
//go:embed expected.json
var expectedData []byte
var expected map[string]any
var network string

func TestMain(m *testing.M) {
network = "mainnet"
if err := json.Unmarshal(expectedData, &expected); err != nil {
panic(err)
}
Expand All @@ -25,7 +27,7 @@ func TestMain(m *testing.M) {
type testFn func(network string, height int64, raw []byte) (map[string]interface{}, error)

func TestCronConstructor(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("CronConstructor", expected)
tests, err := tools.LoadTestData[map[string]any](network, "CronConstructor", expected)
require.NoError(t, err)
runTest(t, cron.CronConstructor, tests)
}
Expand Down
8 changes: 4 additions & 4 deletions actors/datacap/allowance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ import (
type testFn func(network string, height int64, raw, rawReturn []byte) (map[string]interface{}, error)

func TestIncreaseAllowance(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("IncreaseAllowance", expected)
tests, err := tools.LoadTestData[map[string]any](network, "IncreaseAllowance", expected)
require.NoError(t, err)

runTest(t, datacap.IncreaseAllowance, tests)
}

func TestDecreaseAllowance(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("DecreaseAllowance", expected)
tests, err := tools.LoadTestData[map[string]any](network, "DecreaseAllowance", expected)
require.NoError(t, err)

runTest(t, datacap.DecreaseAllowance, tests)
}

func TestRevokeAllowance(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("RevokeAllowance", expected)
tests, err := tools.LoadTestData[map[string]any](network, "RevokeAllowance", expected)
require.NoError(t, err)

runTest(t, datacap.RevokeAllowance, tests)
}

func TestGetAllowance(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("GetAllowance", expected)
tests, err := tools.LoadTestData[map[string]any](network, "GetAllowance", expected)
require.NoError(t, err)

runTest(t, datacap.GetAllowance, tests)
Expand Down
6 changes: 3 additions & 3 deletions actors/datacap/burn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import (
)

func TestBurnExported(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("BurnExported", expected)
tests, err := tools.LoadTestData[map[string]any](network, "BurnExported", expected)
require.NoError(t, err)

runTest(t, datacap.BurnExported, tests)
}

func TestBurnFromExported(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("BurnFromExported", expected)
tests, err := tools.LoadTestData[map[string]any](network, "BurnFromExported", expected)
require.NoError(t, err)

runTest(t, datacap.BurnFromExported, tests)
}

func TestDestroyExported(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("DestroyExported", expected)
tests, err := tools.LoadTestData[map[string]any](network, "DestroyExported", expected)
require.NoError(t, err)

runTest(t, datacap.DestroyExported, tests)
Expand Down
9 changes: 6 additions & 3 deletions actors/datacap/datacap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,32 @@ import (
var expectedData []byte
var expected map[string]any

var network string

func TestMain(m *testing.M) {
network = "mainnet"
if err := json.Unmarshal(expectedData, &expected); err != nil {
panic(err)
}
os.Exit(m.Run())
}

func TestNameExported(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("NameExported", expected)
tests, err := tools.LoadTestData[map[string]any](network, "NameExported", expected)
require.NoError(t, err)

runDatacapTest(t, datacap.NameExported, tests)
}

func TestSymbolExported(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("SymbolExported", expected)
tests, err := tools.LoadTestData[map[string]any](network, "SymbolExported", expected)
require.NoError(t, err)

runDatacapTest(t, datacap.SymbolExported, tests)
}

func TestTotalSupplyExported(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("TotalSupplyExported", expected)
tests, err := tools.LoadTestData[map[string]any](network, "TotalSupplyExported", expected)
require.NoError(t, err)

runDatacapTest(t, datacap.TotalSupplyExported, tests)
Expand Down
2 changes: 1 addition & 1 deletion actors/datacap/granularity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestGranularityExported(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("GranularityExported", expected)
tests, err := tools.LoadTestData[map[string]any](network, "GranularityExported", expected)
require.NoError(t, err)

for _, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion actors/datacap/mint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestMintExported(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("MintExported", expected)
tests, err := tools.LoadTestData[map[string]any](network, "MintExported", expected)
require.NoError(t, err)

runTest(t, datacap.MintExported, tests)
Expand Down
2 changes: 1 addition & 1 deletion actors/datacap/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestTransferExported(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("TransferExported", expected)
tests, err := tools.LoadTestData[map[string]any](network, "TransferExported", expected)
require.NoError(t, err)

runTest(t, datacap.TransferExported, tests)
Expand Down
9 changes: 6 additions & 3 deletions actors/eam/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ import (
"github.com/zondax/fil-parser/types"
)

var network string

//go:embed expected.json
var expectedData []byte
var expected map[string]any

func TestMain(m *testing.M) {
network = "mainnet"
if err := json.Unmarshal(expectedData, &expected); err != nil {
panic(err)
}
Expand All @@ -28,21 +31,21 @@ func TestMain(m *testing.M) {
type testFn func(network string, height int64, raw, rawReturn []byte, msgCid cid.Cid) (map[string]interface{}, *types.AddressInfo, error)

func TestParseCreateExternal(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("CreateExternalExported", expected)
tests, err := tools.LoadTestData[map[string]any](network, "CreateExternalExported", expected)
require.NoError(t, err)

runTest(t, eam.ParseCreateExternal, tests)
}

func TestParseCreate(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("CreateExported", expected)
tests, err := tools.LoadTestData[map[string]any](network, "CreateExported", expected)
require.NoError(t, err)

runTest(t, eam.ParseCreate, tests)
}

func TestParseCreate2(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("Create2Exported", expected)
tests, err := tools.LoadTestData[map[string]any](network, "Create2Exported", expected)
require.NoError(t, err)

runTest(t, eam.ParseCreate2, tests)
Expand Down
16 changes: 9 additions & 7 deletions actors/evm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import (
//go:embed expected.json
var expectedData []byte
var expected map[string]any
var network string

func TestMain(m *testing.M) {
network = "mainnet"
if err := json.Unmarshal(expectedData, &expected); err != nil {
panic(err)
}
Expand All @@ -27,35 +29,35 @@ func TestMain(m *testing.M) {
type testFn func(network string, height int64, raw []byte) (map[string]interface{}, error)

func TestResurrect(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("Resurrect", expected)
tests, err := tools.LoadTestData[map[string]any](network, "Resurrect", expected)
require.NoError(t, err)

runTest(t, evm.Resurrect, tests)
}

func TestGetByteCode(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("GetByteCode", expected)
tests, err := tools.LoadTestData[map[string]any](network, "GetByteCode", expected)
require.NoError(t, err)

runTest(t, evm.GetByteCode, tests)
}

func TestGetByteCodeHash(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("GetByteCodeHash", expected)
tests, err := tools.LoadTestData[map[string]any](network, "GetByteCodeHash", expected)
require.NoError(t, err)

runTest(t, evm.GetByteCodeHash, tests)
}

func TestEVMConstructor(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("EVMConstructor", expected)
tests, err := tools.LoadTestData[map[string]any](network, "EVMConstructor", expected)
require.NoError(t, err)

runTest(t, evm.EVMConstructor, tests)
}

func TestGetStorageAt(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("GetStorageAt", expected)
tests, err := tools.LoadTestData[map[string]any](network, "GetStorageAt", expected)
require.NoError(t, err)

for _, tt := range tests {
Expand All @@ -76,7 +78,7 @@ func TestGetStorageAt(t *testing.T) {
}

func TestInvokeContract(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("InvokeContract", expected)
tests, err := tools.LoadTestData[map[string]any](network, "InvokeContract", expected)
require.NoError(t, err)

for _, tt := range tests {
Expand All @@ -97,7 +99,7 @@ func TestInvokeContract(t *testing.T) {
}

func TestInvokeContractDelegate(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("InvokeContractDelegate", expected)
tests, err := tools.LoadTestData[map[string]any](network, "InvokeContractDelegate", expected)
require.NoError(t, err)

for _, tt := range tests {
Expand Down
9 changes: 6 additions & 3 deletions actors/init/int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import (
var expectedData []byte
var expected map[string]any

var network string

func TestMain(m *testing.M) {
network = "mainnet"
if err := json.Unmarshal(expectedData, &expected); err != nil {
panic(err)
}
Expand All @@ -29,21 +32,21 @@ func TestMain(m *testing.M) {
type testFn func(network string, height int64, msg *parser.LotusMessage, raw []byte) (map[string]interface{}, *types.AddressInfo, error)

func TestParseExec(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("ParseExec", expected)
tests, err := tools.LoadTestData[map[string]any](network, "ParseExec", expected)
require.NoError(t, err)

runTest(t, initActor.ParseExec, tests)
}

func TestParseExec4(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("ParseExec4", expected)
tests, err := tools.LoadTestData[map[string]any](network, "ParseExec4", expected)
require.NoError(t, err)

runTest(t, initActor.ParseExec4, tests)
}

func TestInitConstructor(t *testing.T) {
tests, err := tools.LoadTestData[map[string]any]("InitConstructor", expected)
tests, err := tools.LoadTestData[map[string]any](network, "InitConstructor", expected)
require.NoError(t, err)

for _, tt := range tests {
Expand Down
Loading

0 comments on commit 46b3650

Please sign in to comment.