forked from ethereum-optimism/superchain-registry
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
40 changed files
with
721 additions
and
445 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
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,34 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
|
||
"github.com/ethereum-optimism/superchain-registry/superchain" | ||
) | ||
|
||
type LegacyPlasma struct { | ||
DAChallengeAddress *superchain.Address `json:"da_challenge_address"` | ||
DAChallengeContractAddress *superchain.Address `json:"da_challenge_contract_address"` | ||
DACommitmentType *string `json:"da_commitment_type"` | ||
DAChallengeWindow *uint64 `json:"da_challenge_window"` | ||
DAResolveWindow *uint64 `json:"da_resolve_window"` | ||
UsePlasma *bool `json:"use_plasma"` | ||
PlasmaConfig *interface{} `json:"plasma_config"` | ||
} | ||
|
||
func (lp *LegacyPlasma) CheckNonNilFields() error { | ||
v := reflect.ValueOf(*lp) | ||
typeOfV := v.Type() | ||
|
||
for i := 0; i < v.NumField(); i++ { | ||
field := v.Field(i) | ||
|
||
if field.Kind() == reflect.Ptr && !field.IsNil() { | ||
fieldName := typeOfV.Field(i).Name | ||
return fmt.Errorf("field %s is non-nil", fieldName) | ||
} | ||
} | ||
|
||
return nil | ||
} |
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,33 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestLegacyPlasmaConfig_error(t *testing.T) { | ||
jsonData := `{ | ||
"block_time": 2, | ||
"da_commitment_type": "GenericCommitment" | ||
}` | ||
|
||
var plasmaConfig LegacyPlasma | ||
err := json.Unmarshal([]byte(jsonData), &plasmaConfig) | ||
require.NoError(t, err, "Error unmarshaling JSON: %v", err) | ||
|
||
require.Error(t, plasmaConfig.CheckNonNilFields(), "Expected an error due to non-nil fields, but got nil") | ||
} | ||
|
||
func TestLegacyPlasmaConfig_success(t *testing.T) { | ||
jsonData := `{ | ||
"block_time": 2 | ||
}` | ||
|
||
var plasmaConfig LegacyPlasma | ||
err := json.Unmarshal([]byte(jsonData), &plasmaConfig) | ||
require.NoError(t, err, "Error unmarshaling JSON: %v", err) | ||
|
||
require.NoError(t, plasmaConfig.CheckNonNilFields(), "Expected no error when checking for non nil plasma fields") | ||
} |
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
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.