Skip to content

Commit 9698798

Browse files
Develop (#3)
* temp revert ci * update download * Refactor CI workflow. * Fix ci test --------- Co-authored-by: freehere107 <[email protected]>
1 parent 5b746c2 commit 9698798

File tree

9 files changed

+87
-19
lines changed

9 files changed

+87
-19
lines changed

.github/workflows/ci.yaml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
name: CI
1+
name: Build
22
on:
33
pull_request:
4-
branches: [ "main" ]
4+
branches: ["develop", "main"]
55
push:
66
tags: ["*"]
7+
branches: ["develop", "main"]
78

89
jobs:
910
build-and-deploy:
@@ -23,6 +24,11 @@ jobs:
2324
- uses: olegtarasov/[email protected]
2425
id: tag-name
2526

27+
- uses: benjlevesque/[email protected]
28+
id: short-sha
29+
with:
30+
length: 7
31+
2632
- name: Setup Golang with cache
2733
uses: magnetikonline/action-golang-cache@v4
2834
with:
@@ -43,6 +49,24 @@ jobs:
4349
if: startsWith(github.ref, 'refs/tags/')
4450
with:
4551
context: .
46-
push: true
52+
push: ${{ github.event_name != 'pull_request' }}
4753
tags: quay.io/subscan-explorer/solidity-verification-tool:${{ env.GIT_TAG_NAME }}
48-
labels: ${{ steps.meta.outputs.labels }}
54+
labels: ${{ steps.meta.outputs.labels }}
55+
56+
- name: Build and publish SHA docker image
57+
uses: docker/build-push-action@v3
58+
if: startsWith(github.ref, 'refs/tags/') == false
59+
with:
60+
context: .
61+
push: true
62+
tags: quay.io/subscan-explorer/solidity-verification-tool:sha-${{ env.SHA }}-${{ github.run_number }}
63+
labels: ${{ steps.meta.outputs.labels }}
64+
65+
- uses: 8398a7/action-slack@v3
66+
if: failure()
67+
with:
68+
status: ${{ job.status }}
69+
fields: repo,author,eventName,workflow,ref,commit
70+
channel: ${{ secrets.SLACK_CHANNEL_ID }}
71+
env:
72+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_INCOMING_WEBHOOK_URL }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
tmp
33
static/v*
44
static/0.*
5-
static/resolc
5+
resolc

api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ func verificationHandler(w http.ResponseWriter, r *http.Request) {
9292
return
9393
}
9494

95+
if verified.Status == mismatch {
96+
respondError(w, fmt.Errorf("bytecode mismatch"))
97+
return
98+
}
99+
95100
w.Header().Set("Content-Type", "application/json")
96101
w.WriteHeader(http.StatusOK)
97102
_ = json.NewEncoder(w).Encode(VerificationResponse{VerifiedStatus: verified.Status,

compile.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,8 @@ func BytecodeWithoutMetadata(code string) string {
170170
return code
171171
}
172172
metadataSize := int((numericResult * 2) + 4)
173+
if metadataSize > len(code) {
174+
return code
175+
}
173176
return code[:len(code)-metadataSize]
174177
}

main.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,21 @@ func init() {
2121

2222
func main() {
2323
args := os.Args
24-
switch args[1] {
25-
case "download":
26-
download()
27-
default:
24+
25+
var server = func() {
2826
http.HandleFunc("/verify", verificationHandler)
2927
util.Logger().Info("Server started on :8081")
3028
log.Fatal(http.ListenAndServe(":8081", nil))
3129
}
30+
31+
if len(args) >= 2 {
32+
switch args[1] {
33+
case "download":
34+
download()
35+
default:
36+
server()
37+
}
38+
return
39+
}
40+
server()
3241
}

main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func Test_verificationHandler(t *testing.T) {
251251
if resp.VerifiedStatus != mismatch && resp.VerifiedStatus != perfect || resp.VerifiedStatus == partial {
252252
t.Errorf("verification status not match")
253253
}
254-
if resp.Message != "ok" {
255-
t.Errorf("resp message should be ok")
254+
if resp.Message != "bytecode mismatch" {
255+
t.Errorf("resp message should be bytecode mismatch")
256256
}
257257
}

revive.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func (s *ReviveMetadata) recompileContract(_ context.Context, version string) (*
2626
// ./resolc --solc ./v0.8.17+commit.8df45f5f --standard-json<example_input.json
2727
solcPath := filepath.Join(SolcManagerInstance.cacheDir, "resolc")
2828
cmd := exec.Command(solcPath, "--solc", filepath.Join(SolcManagerInstance.cacheDir, version), "--standard-json")
29-
fmt.Println(cmd)
3029
var stdoutBuf, stderrBuf bytes.Buffer
3130
cmd.Stdout = &stdoutBuf
3231
cmd.Stderr = &stderrBuf
@@ -71,16 +70,26 @@ func download() {
7170
const repo = "paritytech/revive"
7271
apiURL := fmt.Sprintf("https://api.github.com/repos/%s/releases/latest", repo)
7372
fileName := downloadLatestResolc(apiURL)
74-
err := extractAndSetExec(fileName, "static", strings.Replace(fileName, ".tar.gz", "", 1), "resolc")
73+
var err error
74+
if strings.HasSuffix(fileName, ".tar.gz") {
75+
err = extractAndSetExec(fileName, "static", strings.Replace(fileName, ".tar.gz", "", 1), "resolc")
76+
} else {
77+
err = os.Chmod(fileName, 0755)
78+
if err != nil {
79+
panic(err)
80+
}
81+
err = os.Rename(fileName, filepath.Join(SolcManagerInstance.cacheDir, "resolc"))
82+
}
83+
7584
if err != nil {
7685
log.Fatal(err)
7786
}
7887
}
7988

8089
func downloadLatestResolc(apiURL string) string {
81-
fileName := "resolc-x86_64-unknown-linux-musl.tar.gz"
90+
fileName := "resolc-x86_64-unknown-linux-musl"
8291
if runtime.GOOS == "darwin" {
83-
fileName = "resolc-universal-apple-darwin.tar.gz"
92+
fileName = "resolc-universal-apple-darwin"
8493
}
8594

8695
util.Logger().Info(fmt.Sprintf("Start downloading latest resolc binary %s", apiURL))
@@ -102,6 +111,7 @@ func downloadLatestResolc(apiURL string) string {
102111
var downloadURL string
103112
for _, asset := range release.Assets {
104113
if asset.Name == fileName {
114+
util.Debug(asset)
105115
downloadURL = asset.DownloadURL
106116
break
107117
}

revive_test.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ func Test_downloadLatestResolc(t *testing.T) {
2727
_, _ = w.Write([]byte("mock binary content"))
2828
})
2929

30+
mux.HandleFunc("/resolc-x86_64-unknown-linux-musl", func(w http.ResponseWriter, r *http.Request) {
31+
w.WriteHeader(http.StatusOK)
32+
_, _ = w.Write([]byte("mock binary content"))
33+
})
34+
mux.HandleFunc("/resolc-universal-apple-darwin", func(w http.ResponseWriter, r *http.Request) {
35+
w.WriteHeader(http.StatusOK)
36+
_, _ = w.Write([]byte("mock binary content"))
37+
})
38+
3039
// Create a mock server with the ServeMux
3140
mockServer := httptest.NewServer(mux)
3241
// Register multiple handlers
@@ -42,20 +51,28 @@ func Test_downloadLatestResolc(t *testing.T) {
4251
{
4352
"name": "resolc-x86_64-unknown-linux-musl.tar.gz",
4453
"browser_download_url": "%s/resolc-x86_64-unknown-linux-musl.tar.gz"
54+
},
55+
{
56+
"name": "resolc-universal-apple-darwin",
57+
"browser_download_url": "%s/resolc-universal-apple-darwin"
58+
},
59+
{
60+
"name": "resolc-x86_64-unknown-linux-musl",
61+
"browser_download_url": "%s/resolc-x86_64-unknown-linux-musl"
4562
}
4663
]
47-
}`, mockServer.URL, mockServer.URL)))
64+
}`, mockServer.URL, mockServer.URL, mockServer.URL, mockServer.URL)))
4865
})
4966
defer mockServer.Close()
5067

5168
// Call the function with the mock server URL
5269
fileName := downloadLatestResolc(mockServer.URL + "/repos/paritytech/revive/releases/latest")
5370

5471
// Check if the file was downloaded correctly
55-
if runtime.GOOS == "darwin" && fileName != "resolc-universal-apple-darwin.tar.gz" {
72+
if runtime.GOOS == "darwin" && (fileName != "resolc-universal-apple-darwin.tar.gz" && fileName != "resolc-universal-apple-darwin") {
5673
t.Fatalf("expected file name to be resolc-universal-apple-darwin.tar.gz, got %s", fileName)
5774
}
58-
if runtime.GOOS == "linux" && fileName != "resolc-x86_64-unknown-linux-musl.tar.gz" {
75+
if runtime.GOOS == "linux" && (fileName != "resolc-x86_64-unknown-linux-musl.tar.gz" && fileName != "resolc-x86_64-unknown-linux-musl") {
5976
t.Fatalf("expected file name to be resolc-x86_64-unknown-linux-musl.tar.gz, got %s", fileName)
6077
}
6178
}

static/example_metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"evmVersion": "istanbul",
1111
"libraries": {},
1212
"metadata": {
13-
"bytecodeHash": "ipfs"
13+
"bytecodeHash": "none"
1414
},
1515
"optimizer": {
1616
"enabled": true,

0 commit comments

Comments
 (0)