This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpc: transaction receipt test (#678)
* Problem: No test on the transaction receipt api Closes: #582 - add receipt rpc test for erc20 transfer logs * lower gas fee * build with go 1.17 in CI * use go 1.17 in test-solidity * fix merge
- Loading branch information
Showing
9 changed files
with
193 additions
and
38 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
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
File renamed without changes.
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,88 @@ | ||
package types | ||
|
||
import ( | ||
// embed compiled smart contract | ||
_ "embed" | ||
"encoding/hex" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi" | ||
) | ||
|
||
// HexString is a byte array that serializes to hex | ||
type HexString []byte | ||
|
||
// MarshalJSON serializes ByteArray to hex | ||
func (s HexString) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(fmt.Sprintf("%x", string(s))) | ||
} | ||
|
||
// UnmarshalJSON deserializes ByteArray to hex | ||
func (s *HexString) UnmarshalJSON(data []byte) error { | ||
var x string | ||
if err := json.Unmarshal(data, &x); err != nil { | ||
return err | ||
} | ||
str, err := hex.DecodeString(x) | ||
if err != nil { | ||
return err | ||
} | ||
*s = str | ||
return nil | ||
} | ||
|
||
// CompiledContract contains compiled bytecode and abi | ||
type CompiledContract struct { | ||
ABI abi.ABI | ||
Bin HexString | ||
} | ||
|
||
type jsonCompiledContract struct { | ||
ABI string | ||
Bin HexString | ||
} | ||
|
||
// MarshalJSON serializes ByteArray to hex | ||
func (s CompiledContract) MarshalJSON() ([]byte, error) { | ||
abi1, err := json.Marshal(s.ABI) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return json.Marshal(jsonCompiledContract{ABI: string(abi1), Bin: s.Bin}) | ||
} | ||
|
||
// UnmarshalJSON deserializes ByteArray to hex | ||
func (s *CompiledContract) UnmarshalJSON(data []byte) error { | ||
var x jsonCompiledContract | ||
if err := json.Unmarshal(data, &x); err != nil { | ||
return err | ||
} | ||
|
||
s.Bin = x.Bin | ||
if err := json.Unmarshal([]byte(x.ABI), &s.ABI); err != nil { | ||
fmt.Println("unmarshal abi fail", x.ABI, string(data)) | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
var ( | ||
//go:embed ERC20Contract.json | ||
erc20JSON []byte | ||
|
||
// ERC20Contract is the compiled test erc20 contract | ||
ERC20Contract CompiledContract | ||
) | ||
|
||
func init() { | ||
err := json.Unmarshal(erc20JSON, &ERC20Contract) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
if len(ERC20Contract.Bin) == 0 { | ||
panic("load contract failed") | ||
} | ||
} |