Skip to content

Commit 1050aca

Browse files
authored
Merge pull request #1 from chronicleprotocol/sc641-wsteth-integration-test
sc641, add mock for ETHRPC call for WSTETH
2 parents 11ca9ca + cb0b792 commit 1050aca

File tree

6 files changed

+178
-6
lines changed

6 files changed

+178
-6
lines changed

.github/workflows/lint_test.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ jobs:
1212
test:
1313
strategy:
1414
matrix:
15-
go-version: [1.16.x]
15+
go-version: [1.17.x]
1616
os: [ubuntu-latest]
1717
runs-on: ${{ matrix.os }}
1818
steps:
1919
- name: Install Go
20-
uses: actions/setup-go@v2
20+
uses: actions/setup-go@v3
2121
with:
2222
go-version: ${{ matrix.go-version }}
2323
- name: Checkout code
24-
uses: actions/checkout@v2
24+
uses: actions/checkout@v3
2525
- name: Linting code
26-
uses: golangci/golangci-lint-action@v2
26+
uses: golangci/golangci-lint-action@v3
2727
with:
2828
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
29-
version: v1.43
29+
version: v1.44
3030

3131
# Optional: working directory, useful for monorepos
3232
# working-directory: somedir
@@ -50,4 +50,4 @@ jobs:
5050
- name: Run E2E Test
5151
env:
5252
SMOCKER_HOST: "http://localhost"
53-
run: go test ./e2e
53+
run: go test ./e2e

origin/balancerv2.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package origin
2+
3+
// Simulate an ETHRPC node returning the price for STETH/ETH on BalancerV2
4+
// https://etherscan.io/address/0x32296969ef14eb0c6d29669c550d4a0449130230#code
5+
6+
import (
7+
"fmt"
8+
9+
"github.com/chronicleprotocol/infestor/smocker"
10+
)
11+
12+
type BalancerV2 struct{}
13+
14+
func (b BalancerV2) BuildMocks(e []ExchangeMock) ([]*smocker.Mock, error) {
15+
return CombineMocks(e, b.build)
16+
}
17+
18+
func (b BalancerV2) build(e ExchangeMock) (*smocker.Mock, error) {
19+
m := smocker.NewSubstringMatcher("0x32296969ef14eb0c6d29669c550d4a0449130230")
20+
21+
return &smocker.Mock{
22+
Request: smocker.MockRequest{
23+
Method: smocker.NewStringMatcher("POST"),
24+
Path: smocker.NewStringMatcher("/"),
25+
Body: &smocker.BodyMatcher{
26+
BodyString: &m,
27+
},
28+
},
29+
Response: &smocker.MockResponse{
30+
Status: e.StatusCode,
31+
Headers: map[string]smocker.StringSlice{
32+
"Content-Type": []string{
33+
"application/json",
34+
},
35+
},
36+
Body: fmt.Sprintf(rpcJSONResult, "0x0000000000000000000000000000000000000000000000000dd22d6848e229b8"),
37+
},
38+
}, nil
39+
}

origin/curve.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package origin
2+
3+
// Simulate an ETHRPC node returning the price for STETH/ETH on Curve
4+
// https://etherscan.io/address/0xdc24316b9ae028f1497c275eb9192a3ea0f67022#code
5+
6+
import (
7+
"fmt"
8+
9+
"github.com/chronicleprotocol/infestor/smocker"
10+
)
11+
12+
type Curve struct{}
13+
14+
func (b Curve) BuildMocks(e []ExchangeMock) ([]*smocker.Mock, error) {
15+
return CombineMocks(e, b.build)
16+
}
17+
18+
func (b Curve) build(e ExchangeMock) (*smocker.Mock, error) {
19+
m := smocker.NewSubstringMatcher("0xdc24316b9ae028f1497c275eb9192a3ea0f67022")
20+
21+
return &smocker.Mock{
22+
Request: smocker.MockRequest{
23+
Method: smocker.NewStringMatcher("POST"),
24+
Path: smocker.NewStringMatcher("/"),
25+
Body: &smocker.BodyMatcher{
26+
BodyString: &m,
27+
},
28+
},
29+
Response: &smocker.MockResponse{
30+
Status: e.StatusCode,
31+
Headers: map[string]smocker.StringSlice{
32+
"Content-Type": []string{
33+
"application/json",
34+
},
35+
},
36+
Body: fmt.Sprintf(rpcJSONResult, "0x0000000000000000000000000000000000000000000000000dcfcc3d4023b410"),
37+
},
38+
}, nil
39+
}

origin/exchange.go

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ var exchanges = map[string]Mockable{
5151
"okex": Okex{},
5252
"poloniex": Poloniex{},
5353
"upbit": Upbit{},
54+
"wsteth": WSTETH{},
55+
"balancerV2": BalancerV2{},
56+
"curve": Curve{},
5457
}
5558

5659
// Symbol represents an asset pair.

origin/wsteth.go

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package origin
2+
3+
// Simulate an ETHRPC node returning the price for WstETH
4+
// https://etherscan.io/address/0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0#code
5+
6+
import (
7+
"fmt"
8+
9+
"github.com/chronicleprotocol/infestor/smocker"
10+
)
11+
12+
type WSTETH struct{}
13+
14+
const rpcJSONResult = `{
15+
"jsonrpc": "2.0",
16+
"id": 1,
17+
"result": "%s"
18+
}`
19+
20+
func (b WSTETH) BuildMocks(e []ExchangeMock) ([]*smocker.Mock, error) {
21+
mocks := make([]*smocker.Mock, 0)
22+
fmt.Println(mocks)
23+
m, err := CombineMocks(e, b.buildTokensPerStEth)
24+
if err != nil {
25+
return nil, err
26+
}
27+
mocks = append(mocks, m...)
28+
29+
m, err = CombineMocks(e, b.buildstEthPerToken)
30+
if err != nil {
31+
return nil, err
32+
}
33+
mocks = append(mocks, m...)
34+
35+
return mocks, nil
36+
}
37+
38+
func (b WSTETH) buildTokensPerStEth(e ExchangeMock) (*smocker.Mock, error) {
39+
// tokensPerStEth
40+
m := smocker.NewSubstringMatcher("0x9576a0c8")
41+
42+
return &smocker.Mock{
43+
Request: smocker.MockRequest{
44+
Method: smocker.NewStringMatcher("POST"),
45+
Path: smocker.NewStringMatcher("/"),
46+
Body: &smocker.BodyMatcher{
47+
BodyString: &m,
48+
},
49+
},
50+
Response: &smocker.MockResponse{
51+
Status: e.StatusCode,
52+
Headers: map[string]smocker.StringSlice{
53+
"Content-Type": []string{
54+
"application/json",
55+
},
56+
},
57+
Body: fmt.Sprintf(rpcJSONResult, "0x0000000000000000000000000000000000000000000000000cf6c97c561e07bc"),
58+
},
59+
}, nil
60+
}
61+
62+
func (b WSTETH) buildstEthPerToken(e ExchangeMock) (*smocker.Mock, error) {
63+
// stEthPerToken
64+
m := smocker.NewSubstringMatcher("0x035faf82")
65+
66+
return &smocker.Mock{
67+
Request: smocker.MockRequest{
68+
Method: smocker.NewStringMatcher("POST"),
69+
Path: smocker.NewStringMatcher("/"),
70+
Body: &smocker.BodyMatcher{
71+
BodyString: &m,
72+
},
73+
},
74+
Response: &smocker.MockResponse{
75+
Status: e.StatusCode,
76+
Headers: map[string]smocker.StringSlice{
77+
"Content-Type": []string{
78+
"application/json",
79+
},
80+
},
81+
Body: fmt.Sprintf(rpcJSONResult, "0x0000000000000000000000000000000000000000000000000edb20f642b06506"),
82+
},
83+
}, nil
84+
}

smocker/mock.go

+7
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,10 @@ func NewStringMatcher(value string) StringMatcher {
8888
Value: value,
8989
}
9090
}
91+
92+
func NewSubstringMatcher(value string) StringMatcher {
93+
return StringMatcher{
94+
Matcher: "ShouldContainSubstring",
95+
Value: value,
96+
}
97+
}

0 commit comments

Comments
 (0)