Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update solidity version #21

Merged
merged 7 commits into from
Oct 22, 2024
44 changes: 44 additions & 0 deletions abi/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,49 @@ func TestEncoding(t *testing.T) {
}
}

func TestEncoding2(t *testing.T) {
cases := []struct {
Type string
Input interface{}
}{
{
"tuple(bytes a)[]",
[]map[string]interface{}{
{
"a": []byte{
0xff,
0xff,
},
},
{
"a": []byte{
0xff,
0xff,
},
},
},
},
}

server := testutil.NewTestServer(t)

for _, c := range cases {
c := c
t.Run(c.Type, func(t *testing.T) {
t.Parallel()

tt, err := NewType(c.Type)
if err != nil {
t.Fatal(err)
}

if err := testEncodeDecode(t, server, tt, c.Input); err != nil {
t.Fatal(err)
}
})
}
}
luka-ciric-ethernal marked this conversation as resolved.
Show resolved Hide resolved

func TestEncodingBestEffort(t *testing.T) {
strAddress := "0xdbb881a51CD4023E4400CEF3ef73046743f08da3"
ethAddress := ethgo.HexToAddress(strAddress)
Expand Down Expand Up @@ -566,6 +609,7 @@ func TestEncodingArguments(t *testing.T) {

func testEncodeDecode(t *testing.T, server *testutil.TestServer, tt *Type, input interface{}) error {
res1, err := Encode(input, tt)
fmt.Println(res1)
luka-ciric-ethernal marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion abi/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/Ethernal-Tech/ethgo"
"github.com/Ethernal-Tech/ethgo/compiler"
)

func randomInt(min, max int) int {
Expand Down Expand Up @@ -192,7 +193,7 @@ func (g *generateContractImpl) run(t *Type) string {
}

contractTemplate :=
`pragma solidity ^0.8.19;
`pragma solidity ^%s;

contract Sample {
// structs
Expand All @@ -204,6 +205,7 @@ func (g *generateContractImpl) run(t *Type) string {

contract := fmt.Sprintf(
contractTemplate,
compiler.SolcVersion,
strings.Join(g.structs, "\n"),
strings.Join(input, ","),
strings.Join(output, ","),
Expand Down
4 changes: 4 additions & 0 deletions compiler/solidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"strings"
)

const (
SolcVersion = "0.8.19"
)

type Output struct {
Contracts map[string]*Artifact
Sources map[string]*Source
Expand Down
10 changes: 5 additions & 5 deletions compiler/solidity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func init() {
panic(err)
}
// solc folder does not exists
if err := DownloadSolidity("0.8.19", solcDir, false); err != nil {
if err := DownloadSolidity(SolcVersion, solcDir, false); err != nil {
panic(err)
}
}
Expand Down Expand Up @@ -134,13 +134,13 @@ func TestDownloadSolidityCompiler(t *testing.T) {
}
defer os.RemoveAll(dst1)

if err := DownloadSolidity("0.8.19", dst1, true); err != nil {
if err := DownloadSolidity(SolcVersion, dst1, true); err != nil {
t.Fatal(err)
}
if existsSolidity(t, filepath.Join(dst1, "solidity")) {
t.Fatal("it should not exist")
}
if !existsSolidity(t, filepath.Join(dst1, "solidity-0.8.19")) {
if !existsSolidity(t, filepath.Join(dst1, "solidity-"+SolcVersion)) {
t.Fatal("it should exist")
}

Expand All @@ -150,13 +150,13 @@ func TestDownloadSolidityCompiler(t *testing.T) {
}
defer os.RemoveAll(dst2)

if err := DownloadSolidity("0.8.19", dst2, false); err != nil {
if err := DownloadSolidity(SolcVersion, dst2, false); err != nil {
t.Fatal(err)
}
if !existsSolidity(t, filepath.Join(dst2, "solidity")) {
t.Fatal("it should exist")
}
if existsSolidity(t, filepath.Join(dst2, "solidity-0.8.19")) {
if existsSolidity(t, filepath.Join(dst2, "solidity-"+SolcVersion)) {
t.Fatal("it should not exist")
}
}
2 changes: 1 addition & 1 deletion testutil/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (c *Contract) GetEvent(name string) *Event {

// Print prints the contract
func (c *Contract) Print() string {
str := "pragma solidity ^0.8.19;\n"
str := "pragma solidity ^" + compiler.SolcVersion + ";\n"
str += "\n"
str += "contract Sample {\n"

Expand Down
Loading