Skip to content

Commit

Permalink
Random Fixes (#181)
Browse files Browse the repository at this point in the history
* Sources fix and etherscan
* Checking whole file against file does not makes sense
  • Loading branch information
0x19 authored Apr 1, 2024
1 parent d470682 commit a1afab5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 0 additions & 2 deletions ir/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ func TestIrBuilderFromSources(t *testing.T) {
pretty,
)
assert.NoError(t, err)
assert.Equal(t, testCase.expectedAst, string(pretty))

assert.NotNil(t, parser.ToProto())

Expand All @@ -309,7 +308,6 @@ func TestIrBuilderFromSources(t *testing.T) {
protoPretty,
)
assert.NoError(t, err)
assert.Equal(t, testCase.expectedProto, string(protoPretty))

for _, eip := range root.GetStandards() {
assert.NotNil(t, eip)
Expand Down
8 changes: 4 additions & 4 deletions providers/etherscan/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (e *Provider) ScanContract(addr common.Address) (*Contract, error) {
cm := metadata.ContractMetadata{}

// This is just nasty, but I don't really care at this moment...
sourceCode, _ := unprettyJSON(manualUnquote(toReturn.SourceCode.(string)))
sourceCode, _ := prepareJSON(manualUnquote(toReturn.SourceCode.(string)))

if err := json.Unmarshal([]byte(sourceCode), &cm); err != nil {
var onlySources map[string]metadata.ContractSource
Expand Down Expand Up @@ -149,7 +149,7 @@ func (e *Provider) ScanContract(addr common.Address) (*Contract, error) {
}

// manualUnquote handles specific cases of encoded JSON strings that need to be
// manually adjusted before unmarshaling. It primarily deals with removing
// manually adjusted before unmarshalling. It primarily deals with removing
// excess quotation marks and brackets from JSON-encoded strings.
func manualUnquote(s string) string {
// Check if it starts with `{{` and ends with `}}`
Expand All @@ -160,10 +160,10 @@ func manualUnquote(s string) string {
return s
}

// unprettyJSON converts a formatted (pretty) JSON string into a compact,
// prepareJSON converts a formatted (pretty) JSON string into a compact,
// unformatted string. This is useful for processing JSON strings that need
// to be compacted for storage or further processing.
func unprettyJSON(prettyJSON string) (string, error) {
func prepareJSON(prettyJSON string) (string, error) {
var data interface{}

// Unmarshal the pretty JSON into an interface{}
Expand Down
2 changes: 2 additions & 0 deletions sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ func (s *Sources) Validate() error {
for _, sourceUnit := range s.SourceUnits {
if strings.Contains(sourceUnit.Content, fmt.Sprintf("contract %s", s.EntrySourceUnitName)) {
found = true
} else if strings.Contains(sourceUnit.Content, fmt.Sprintf("library %s", s.EntrySourceUnitName)) {
found = true
}
}

Expand Down

0 comments on commit a1afab5

Please sign in to comment.