-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eeafe95
commit 22532c5
Showing
12 changed files
with
275 additions
and
102 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
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
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,47 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/keystore" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestShowAccounts(t *testing.T) { | ||
r := require.New(t) | ||
|
||
dir := t.TempDir() | ||
cfg.KeyDirPath = dir | ||
scannerKeyStore := keystore.NewKeyStore(dir, keystore.StandardScryptN, keystore.StandardScryptP) | ||
|
||
_, err := scannerKeyStore.NewAccount("Forta123") | ||
r.NoError(err) | ||
|
||
r.NoError(handleFortaAccountAddress(nil, nil)) | ||
} | ||
|
||
func TestShowAccounts_NoAccounts(t *testing.T) { | ||
r := require.New(t) | ||
|
||
dir := t.TempDir() | ||
cfg.KeyDirPath = dir | ||
keystore.NewKeyStore(dir, keystore.StandardScryptN, keystore.StandardScryptP) | ||
|
||
r.Error(handleFortaAccountAddress(nil, nil)) | ||
} | ||
|
||
func TestShowAccounts_MultipleAccounts(t *testing.T) { | ||
r := require.New(t) | ||
|
||
dir := t.TempDir() | ||
cfg.KeyDirPath = dir | ||
scannerKeyStore := keystore.NewKeyStore(dir, keystore.StandardScryptN, keystore.StandardScryptP) | ||
|
||
_, err := scannerKeyStore.NewAccount("Forta123") | ||
r.NoError(err) | ||
|
||
_, err = scannerKeyStore.NewAccount("Forta456") | ||
r.NoError(err) | ||
|
||
r.Error(handleFortaAccountAddress(nil, nil)) | ||
} |
This file was deleted.
Oops, something went wrong.
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,135 @@ | ||
package cmd | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/keystore" | ||
"github.com/forta-network/forta-core-go/registry" | ||
mock_registry "github.com/forta-network/forta-core-go/registry/mocks" | ||
"github.com/forta-network/forta-core-go/security" | ||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const ( | ||
testPoolID = int64(123) | ||
) | ||
|
||
func TestPoolAuthorization(t *testing.T) { | ||
r := require.New(t) | ||
|
||
ctrl := gomock.NewController(t) | ||
regClient := mock_registry.NewMockClient(ctrl) | ||
|
||
dir := t.TempDir() | ||
scannerKeyStore := keystore.NewKeyStore(dir, keystore.StandardScryptN, keystore.StandardScryptP) | ||
|
||
_, err := scannerKeyStore.NewAccount("Forta123") | ||
r.NoError(err) | ||
|
||
scannerKey, err := security.LoadKeyWithPassphrase(dir, "Forta123") | ||
r.NoError(err) | ||
|
||
regClient.EXPECT().SetRegistryChainID(cfg.Registry.ChainID) | ||
regClient.EXPECT().GetPoolScanner(scannerKey.Address.Hex()).Return(nil, nil) | ||
regClient.EXPECT().WillNewScannerShutdownPool(big.NewInt(testPoolID)).Return(false, nil) | ||
regClient.EXPECT().GenerateScannerRegistrationSignature(gomock.Any()).Return(®istry.ScannerRegistrationInfo{}, nil) | ||
|
||
err = authorizePoolWithRegistry(regClient, scannerKey, testPoolID, false, false, false) | ||
r.NoError(err) | ||
} | ||
|
||
func TestPoolAuthorization_ScannerExists(t *testing.T) { | ||
r := require.New(t) | ||
|
||
ctrl := gomock.NewController(t) | ||
regClient := mock_registry.NewMockClient(ctrl) | ||
|
||
dir := t.TempDir() | ||
scannerKeyStore := keystore.NewKeyStore(dir, keystore.StandardScryptN, keystore.StandardScryptP) | ||
|
||
_, err := scannerKeyStore.NewAccount("Forta123") | ||
r.NoError(err) | ||
|
||
scannerKey, err := security.LoadKeyWithPassphrase(dir, "Forta123") | ||
r.NoError(err) | ||
|
||
regClient.EXPECT().SetRegistryChainID(cfg.Registry.ChainID) | ||
regClient.EXPECT().GetPoolScanner(scannerKey.Address.Hex()).Return(®istry.Scanner{}, nil) | ||
|
||
err = authorizePoolWithRegistry(regClient, scannerKey, testPoolID, false, false, false) | ||
r.NoError(err) | ||
} | ||
|
||
func TestPoolAuthorization_Polygonscan(t *testing.T) { | ||
r := require.New(t) | ||
|
||
ctrl := gomock.NewController(t) | ||
regClient := mock_registry.NewMockClient(ctrl) | ||
|
||
dir := t.TempDir() | ||
scannerKeyStore := keystore.NewKeyStore(dir, keystore.StandardScryptN, keystore.StandardScryptP) | ||
|
||
_, err := scannerKeyStore.NewAccount("Forta123") | ||
r.NoError(err) | ||
|
||
scannerKey, err := security.LoadKeyWithPassphrase(dir, "Forta123") | ||
r.NoError(err) | ||
|
||
regClient.EXPECT().SetRegistryChainID(cfg.Registry.ChainID) | ||
regClient.EXPECT().GetPoolScanner(scannerKey.Address.Hex()).Return(nil, nil) | ||
regClient.EXPECT().WillNewScannerShutdownPool(big.NewInt(testPoolID)).Return(false, nil) | ||
regClient.EXPECT().GenerateScannerRegistrationSignature(gomock.Any()).Return(®istry.ScannerRegistrationInfo{}, nil) | ||
|
||
err = authorizePoolWithRegistry(regClient, scannerKey, testPoolID, true, false, false) | ||
r.NoError(err) | ||
} | ||
|
||
func TestPoolAuthorization_GenerateForRegisteredScanner(t *testing.T) { | ||
r := require.New(t) | ||
|
||
ctrl := gomock.NewController(t) | ||
regClient := mock_registry.NewMockClient(ctrl) | ||
|
||
dir := t.TempDir() | ||
scannerKeyStore := keystore.NewKeyStore(dir, keystore.StandardScryptN, keystore.StandardScryptP) | ||
|
||
_, err := scannerKeyStore.NewAccount("Forta123") | ||
r.NoError(err) | ||
|
||
scannerKey, err := security.LoadKeyWithPassphrase(dir, "Forta123") | ||
r.NoError(err) | ||
|
||
regClient.EXPECT().SetRegistryChainID(cfg.Registry.ChainID) | ||
regClient.EXPECT().GetPoolScanner(scannerKey.Address.Hex()).Return(®istry.Scanner{}, nil) | ||
regClient.EXPECT().WillNewScannerShutdownPool(big.NewInt(testPoolID)).Return(false, nil) | ||
regClient.EXPECT().GenerateScannerRegistrationSignature(gomock.Any()).Return(®istry.ScannerRegistrationInfo{}, nil) | ||
|
||
err = authorizePoolWithRegistry(regClient, scannerKey, testPoolID, false, true, false) | ||
r.NoError(err) | ||
} | ||
|
||
func TestPoolAuthorization_CleanOutput(t *testing.T) { | ||
r := require.New(t) | ||
|
||
ctrl := gomock.NewController(t) | ||
regClient := mock_registry.NewMockClient(ctrl) | ||
|
||
dir := t.TempDir() | ||
scannerKeyStore := keystore.NewKeyStore(dir, keystore.StandardScryptN, keystore.StandardScryptP) | ||
|
||
_, err := scannerKeyStore.NewAccount("Forta123") | ||
r.NoError(err) | ||
|
||
scannerKey, err := security.LoadKeyWithPassphrase(dir, "Forta123") | ||
r.NoError(err) | ||
|
||
regClient.EXPECT().SetRegistryChainID(cfg.Registry.ChainID) | ||
regClient.EXPECT().GetPoolScanner(scannerKey.Address.Hex()).Return(nil, nil) | ||
regClient.EXPECT().WillNewScannerShutdownPool(big.NewInt(testPoolID)).Return(false, nil) | ||
regClient.EXPECT().GenerateScannerRegistrationSignature(gomock.Any()).Return(®istry.ScannerRegistrationInfo{}, nil) | ||
|
||
err = authorizePoolWithRegistry(regClient, scannerKey, testPoolID, false, false, true) | ||
r.NoError(err) | ||
} |
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
Oops, something went wrong.