Skip to content

Commit

Permalink
added first test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidu28 committed Feb 9, 2024
1 parent ce2c11a commit cafb9a3
Show file tree
Hide file tree
Showing 8 changed files with 610 additions and 87 deletions.
284 changes: 284 additions & 0 deletions bindings/BeaconChainProofs.go

Large diffs are not rendered by default.

138 changes: 138 additions & 0 deletions build/BeaconChainProofs.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
[
{
"inputs": [
{
"internalType": "bytes32",
"name": "latestBlockRoot",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "beaconStateRoot",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "stateRootProof",
"type": "bytes"
}
],
"name": "verifyStateRootAgainstLatestBlockRoot",
"outputs": [],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "beaconStateRoot",
"type": "bytes32"
},
{
"internalType": "bytes32[]",
"name": "validatorFields",
"type": "bytes32[]"
},
{
"internalType": "bytes",
"name": "validatorFieldsProof",
"type": "bytes"
},
{
"internalType": "uint40",
"name": "validatorIndex",
"type": "uint40"
}
],
"name": "verifyValidatorFields",
"outputs": [],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "beaconStateRoot",
"type": "bytes32"
},
{
"internalType": "bytes32[]",
"name": "withdrawalFields",
"type": "bytes32[]"
},
{
"components": [
{
"internalType": "bytes",
"name": "withdrawalProof",
"type": "bytes"
},
{
"internalType": "bytes",
"name": "slotProof",
"type": "bytes"
},
{
"internalType": "bytes",
"name": "executionPayloadProof",
"type": "bytes"
},
{
"internalType": "bytes",
"name": "timestampProof",
"type": "bytes"
},
{
"internalType": "bytes",
"name": "historicalSummaryBlockRootProof",
"type": "bytes"
},
{
"internalType": "uint64",
"name": "blockRootIndex",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "historicalSummaryIndex",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "withdrawalIndex",
"type": "uint64"
},
{
"internalType": "bytes32",
"name": "blockRoot",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "slotRoot",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "timestampRoot",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "executionPayloadRoot",
"type": "bytes32"
}
],
"internalType": "struct BeaconChainProofs.WithdrawalProof",
"name": "withdrawalProof",
"type": "tuple"
}
],
"name": "verifyWithdrawal",
"outputs": [],
"stateMutability": "view",
"type": "function"
}
]
1 change: 1 addition & 0 deletions build/Endian.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions build/Merkle.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
20 changes: 10 additions & 10 deletions merkle_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func setupSuite() {

//ParseCapellaBeaconState(stateFile)

stateJSON, err := parseJSONFile(stateFile)
stateJSON, err := ParseJSONFile(stateFile)
if err != nil {
fmt.Println("error with JSON parsing beacon state")
}
Expand Down Expand Up @@ -140,7 +140,7 @@ func TestProveWithdrawals(t *testing.T) {
return
}

historicalSummaryStateJSON, err := parseJSONFile("data/deneb_goerli_slot_7421952.json")
historicalSummaryStateJSON, err := ParseJSONFile("data/deneb_goerli_slot_7421952.json")
if err != nil {
fmt.Println("error parsing historicalSummaryState JSON")
}
Expand Down Expand Up @@ -289,7 +289,7 @@ func TestProveBeaconTopLevelRootAgainstBeaconState(t *testing.T) {
func TestGetHistoricalSummariesBlockRootsProofProof(t *testing.T) {

//curl -H "Accept: application/json" https://data.spiceai.io/goerli/beacon/eth/v2/debug/beacon/states/7431952 -o deneb_goerli_slot_7431952.json --header 'X-API-Key: 343035|8b6ddd9b31f54c07b3fc18282b30f61c'
currentBeaconStateJSON, err := parseJSONFile("data/deneb_goerli_slot_7431952.json")
currentBeaconStateJSON, err := ParseJSONFile("data/deneb_goerli_slot_7431952.json")

if err != nil {
fmt.Println("error parsing currentBeaconStateJSON")
Expand All @@ -298,7 +298,7 @@ func TestGetHistoricalSummariesBlockRootsProofProof(t *testing.T) {
//this is not the beacon state of the slot containing the old withdrawal we want to prove but rather
// its the state that was merkleized to create a historical summary containing the slot that has that withdrawal
//, ie, 7421952 mod 8192 = 0 and 7421952 - 7421951 < 8192
oldBeaconStateJSON, err := parseJSONFile("data/deneb_goerli_slot_7421952.json")
oldBeaconStateJSON, err := ParseJSONFile("data/deneb_goerli_slot_7421952.json")
if err != nil {
fmt.Println("error parsing oldBeaconStateJSON")
}
Expand Down Expand Up @@ -352,15 +352,15 @@ func TestGetHistoricalSummariesBlockRootsProofProof(t *testing.T) {
func TestGetHistoricalSummariesBlockRootsProofProofCapellaAgainstDeneb(t *testing.T) {

//curl -H "Accept: application/json" https://data.spiceai.io/goerli/beacon/eth/v2/debug/beacon/states/7431952 -o deneb_goerli_slot_7431952.json --header 'X-API-Key: 343035|8b6ddd9b31f54c07b3fc18282b30f61c'
currentBeaconStateJSON, err := parseJSONFile("data/deneb_goerli_slot_7431952.json")
currentBeaconStateJSON, err := ParseJSONFile("data/deneb_goerli_slot_7431952.json")

if err != nil {
fmt.Println("error parsing currentBeaconStateJSON")
}

//this is not the beacon state of the slot containing the old withdrawal we want to proof but rather
// its the state that was merklized to create a historical summary containing the slot that has that withdrawal, ie, 7421952 mod 8192 = 0
oldBeaconStateJSON, err := parseJSONFileCapella("data/goerli_slot_6397952.json")
oldBeaconStateJSON, err := ParseJSONFileCapella("data/goerli_slot_6397952.json")
if err != nil {
fmt.Println("error parsing oldBeaconStateJSON", err)
}
Expand Down Expand Up @@ -544,7 +544,7 @@ func TestStateRootAgainstLatestBlockHeaderProof(t *testing.T) {

// this is the state where the latest block header from the oracle was taken. This is the next slot after
// the state we want to prove things about (remember latestBlockHeader.state_root = previous slot's state root)
// oracleStateJSON, err := parseJSONFile("data/historical_summary_proof/goerli_slot_6399999.json")
// oracleStateJSON, err := ParseJSONFile("data/historical_summary_proof/goerli_slot_6399999.json")
// var oracleState deneb.BeaconState
// ParseCapellaBeaconStateFromJSON(*oracleStateJSON, &oracleState)

Expand All @@ -555,7 +555,7 @@ func TestStateRootAgainstLatestBlockHeaderProof(t *testing.T) {
}

//the state from the prev slot which contains shit we wanna prove about
stateToProveJSON, err := parseJSONFile("data/deneb_goerli_slot_7413760.json")
stateToProveJSON, err := ParseJSONFile("data/deneb_goerli_slot_7413760.json")
if err != nil {
fmt.Println("error with parsing JSON state file", err)
}
Expand Down Expand Up @@ -782,7 +782,7 @@ type Proofs struct {
WithdrawalFields []string `json:"WithdrawalFields"`
}

func parseJSONFile(filePath string) (*beaconStateJSONDeneb, error) {
func ParseJSONFile(filePath string) (*beaconStateJSONDeneb, error) {
data, err := os.ReadFile(filePath)

if err != nil {
Expand All @@ -801,7 +801,7 @@ func parseJSONFile(filePath string) (*beaconStateJSONDeneb, error) {
return &actualData, nil
}

func parseJSONFileCapella(filePath string) (*beaconStateJSONCapella, error) {
func ParseJSONFileCapella(filePath string) (*beaconStateJSONCapella, error) {
data, err := os.ReadFile(filePath)

if err != nil {
Expand Down
77 changes: 0 additions & 77 deletions onchain_test.go

This file was deleted.

Loading

0 comments on commit cafb9a3

Please sign in to comment.