-
Notifications
You must be signed in to change notification settings - Fork 2
use source of truth contract to derive addresses #3
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
Open
parkan
wants to merge
3
commits into
master
Choose a base branch
from
feat/wagmi
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,105 @@ | ||
| //go:build integration | ||
|
|
||
| package constants | ||
|
|
||
| import ( | ||
| "context" | ||
| "math/big" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/ethereum/go-ethereum" | ||
| "github.com/ethereum/go-ethereum/accounts/abi" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/ethclient" | ||
| ) | ||
|
|
||
| // minimal ABIs - Payments.accounts is the most reliable test | ||
| var paymentsABI = `[{"name":"accounts","type":"function","inputs":[{"name":"token","type":"address"},{"name":"owner","type":"address"}],"outputs":[{"name":"balance","type":"uint256"},{"name":"lockedBalance","type":"uint256"}],"stateMutability":"view"}]` | ||
|
|
||
| type contractTest struct { | ||
| name string | ||
| address common.Address | ||
| } | ||
|
|
||
| func TestGeneratedAddresses_MainnetContracts(t *testing.T) { | ||
| testContracts(t, NetworkMainnet, RPCURLs[NetworkMainnet]) | ||
| } | ||
|
|
||
| func TestGeneratedAddresses_CalibrationContracts(t *testing.T) { | ||
| testContracts(t, NetworkCalibration, RPCURLs[NetworkCalibration]) | ||
| } | ||
|
|
||
| func testContracts(t *testing.T, network Network, rpcURL string) { | ||
| ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
| defer cancel() | ||
|
|
||
| client, err := ethclient.DialContext(ctx, rpcURL) | ||
| if err != nil { | ||
| t.Fatalf("failed to connect to %s: %v", network, err) | ||
| } | ||
| defer client.Close() | ||
|
|
||
| // verify we can reach the network | ||
| chainID, err := client.ChainID(ctx) | ||
| if err != nil { | ||
| t.Fatalf("failed to get chain ID: %v", err) | ||
| } | ||
| t.Logf("connected to %s (chain ID: %d)", network, chainID) | ||
|
|
||
| tests := []contractTest{ | ||
| {"Payments", PaymentsAddresses[network]}, | ||
| {"StateView", WarmStorageStateViewAddresses[network]}, | ||
| {"PDPVerifier", PDPVerifierAddresses[network]}, | ||
| {"SPRegistry", SPRegistryAddresses[network]}, | ||
| {"SessionKeyRegistry", SessionKeyRegistryAddresses[network]}, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| // verify contract has code deployed | ||
| code, err := client.CodeAt(ctx, tc.address, nil) | ||
| if err != nil { | ||
| t.Fatalf("failed to get code at %s: %v", tc.address.Hex(), err) | ||
| } | ||
| if len(code) == 0 { | ||
| t.Fatalf("no code at %s - not a contract", tc.address.Hex()) | ||
| } | ||
| t.Logf("%s: %s (%d bytes)", tc.name, tc.address.Hex(), len(code)) | ||
| }) | ||
| } | ||
|
|
||
| // deeper test: verify Payments contract responds to known method | ||
| t.Run("Payments_ABI", func(t *testing.T) { | ||
| parsed, err := abi.JSON(strings.NewReader(paymentsABI)) | ||
| if err != nil { | ||
| t.Fatalf("failed to parse ABI: %v", err) | ||
| } | ||
|
|
||
| zeroAddr := common.Address{} | ||
| data, err := parsed.Pack("accounts", zeroAddr, zeroAddr) | ||
| if err != nil { | ||
| t.Fatalf("failed to pack accounts call: %v", err) | ||
| } | ||
|
|
||
| paymentsAddr := PaymentsAddresses[network] | ||
| result, err := client.CallContract(ctx, ethereum.CallMsg{ | ||
| To: &paymentsAddr, | ||
| Data: data, | ||
| }, nil) | ||
| if err != nil { | ||
| t.Fatalf("accounts() call failed: %v", err) | ||
| } | ||
|
|
||
| // unpack and verify we get two uint256 values | ||
| var balance, lockedBalance *big.Int | ||
| unpacked, err := parsed.Unpack("accounts", result) | ||
| if err != nil { | ||
| t.Fatalf("failed to unpack: %v", err) | ||
| } | ||
| balance = unpacked[0].(*big.Int) | ||
| lockedBalance = unpacked[1].(*big.Int) | ||
| t.Logf("Payments.accounts(0x0, 0x0) = {balance: %s, locked: %s}", balance, lockedBalance) | ||
| }) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generator and CI job will fail if the Glif RPC endpoints are unavailable during
go generate. This could block CI for unrelated PRs if there's an RPC outage.A few options to consider:
addresses_generated.goand only fail CI if addresses actually changed (vs just failing to fetch)verify-addressesjob ascontinue-on-error: truewith a warning instead of failure on network errorsNot blocking, but worth considering for resilience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, I will make it continue if glif is down, it seems like the importance of this mechanism is still somewhat under debate upstream so I'm not going to overindex on it