-
Notifications
You must be signed in to change notification settings - Fork 16
MorphTx enhance & implement reference key #282
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
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
a8a8cae
update morph tx
739f07b
add reference
2a10ba9
update
9ab3adf
update
f622530
add test
837c403
Merge branch 'main' into ref_key
f0520fa
fix sth
8b336fb
add check and test
029260f
add test
846ff39
refactor: encode MorphTx version as prefix byte instead of RLP field …
FletcherMan a3bcaeb
fix decode morphtx & receipt
909e2dc
fix get transaction hashes by reference
0097c2a
update args
e912d45
fix args checks
cdcfef6
fix version check
2467803
some improve
4ebfb51
add args check
f748d29
update
93de611
Merge branch 'main' into ref_key
8609210
update
73b8a05
update to jade
702d5ce
active after jade fork time
21d0c83
check geth version
a805e93
fix sth
711985c
fix reference validate
9363125
fix memo validate
7822427
fix tx filter
df6a3d6
fix rpc and ref index
f006b23
fix
cba42b4
fix version
1887bfa
add validate
ddd20a8
update returns receipt & result
25b0048
fix: use hexutil.Uint64 for MorphTx version JSON encoding (#293)
panos-xyz 7892e9b
fix hash
dd7be94
add version check and test
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
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,183 @@ | ||
| package bind | ||
|
|
||
| import ( | ||
| "math/big" | ||
| "testing" | ||
|
|
||
| "github.com/morph-l2/go-ethereum/common" | ||
| "github.com/morph-l2/go-ethereum/core/types" | ||
| ) | ||
|
|
||
| func versionPtr(v uint8) *uint8 { | ||
| return &v | ||
| } | ||
|
|
||
| func refTestPtr(r common.Reference) *common.Reference { | ||
| return &r | ||
| } | ||
|
|
||
| func memoTestPtr(b []byte) *[]byte { | ||
| return &b | ||
| } | ||
|
|
||
| // TestMorphTxVersion_HeuristicDefault tests the heuristic version defaulting logic | ||
| // in morphTxVersion(): | ||
| // - Version == nil + no V1 fields → V0 | ||
| // - Version == nil + Reference or Memo → V1 | ||
| // - Explicit Version → use as-is (with validation) | ||
| func TestMorphTxVersion_HeuristicDefault(t *testing.T) { | ||
| ref := common.HexToReference("0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") | ||
| emptyRef := common.Reference{} | ||
| memo := []byte("test memo") | ||
| emptyMemo := []byte{} | ||
|
|
||
| bc := &BoundContract{} // morphTxVersion doesn't use BoundContract fields | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| opts *TransactOpts | ||
| wantVersion uint8 | ||
| wantErr error | ||
| }{ | ||
| // === Heuristic defaults (Version == nil) === | ||
| { | ||
| name: "nil Version, FeeTokenID > 0, no V1 fields → V0", | ||
| opts: &TransactOpts{FeeTokenID: 1}, | ||
| wantVersion: types.MorphTxVersion0, | ||
| }, | ||
| { | ||
| name: "nil Version, FeeTokenID > 0, with Reference → V1", | ||
| opts: &TransactOpts{FeeTokenID: 1, Reference: refTestPtr(ref)}, | ||
| wantVersion: types.MorphTxVersion1, | ||
| }, | ||
| { | ||
| name: "nil Version, FeeTokenID > 0, with Memo → V1", | ||
| opts: &TransactOpts{FeeTokenID: 1, Memo: memoTestPtr(memo)}, | ||
| wantVersion: types.MorphTxVersion1, | ||
| }, | ||
| { | ||
| name: "nil Version, FeeTokenID > 0, with Reference + Memo → V1", | ||
| opts: &TransactOpts{FeeTokenID: 1, Reference: refTestPtr(ref), Memo: memoTestPtr(memo)}, | ||
| wantVersion: types.MorphTxVersion1, | ||
| }, | ||
| { | ||
| name: "nil Version, FeeTokenID = 0, with Reference → V1", | ||
| opts: &TransactOpts{FeeTokenID: 0, Reference: refTestPtr(ref)}, | ||
| wantVersion: types.MorphTxVersion1, | ||
| }, | ||
| { | ||
| name: "nil Version, FeeTokenID = 0, with Memo → V1", | ||
| opts: &TransactOpts{FeeTokenID: 0, Memo: memoTestPtr(memo)}, | ||
| wantVersion: types.MorphTxVersion1, | ||
| }, | ||
| { | ||
| name: "nil Version, FeeTokenID = 0, no V1 fields → V0", | ||
| opts: &TransactOpts{FeeTokenID: 0}, | ||
| wantVersion: types.MorphTxVersion0, | ||
| }, | ||
| { | ||
| name: "nil Version, empty Reference → V0", | ||
| opts: &TransactOpts{FeeTokenID: 1, Reference: refTestPtr(emptyRef)}, | ||
| wantVersion: types.MorphTxVersion0, | ||
| }, | ||
| { | ||
| name: "nil Version, empty Memo → V0", | ||
| opts: &TransactOpts{FeeTokenID: 1, Memo: memoTestPtr(emptyMemo)}, | ||
| wantVersion: types.MorphTxVersion0, | ||
| }, | ||
| { | ||
| name: "nil Version, nil Reference, nil Memo → V0", | ||
| opts: &TransactOpts{FeeTokenID: 1, Reference: nil, Memo: nil}, | ||
| wantVersion: types.MorphTxVersion0, | ||
| }, | ||
|
|
||
| // === V1 heuristic with illegal params === | ||
| { | ||
| name: "nil Version, Reference + FeeTokenID=0 + FeeLimit > 0 → error", | ||
| opts: &TransactOpts{FeeTokenID: 0, FeeLimit: big.NewInt(100), Reference: refTestPtr(ref)}, | ||
| wantErr: types.ErrMorphTxV1IllegalExtraParams, | ||
| }, | ||
| { | ||
| name: "nil Version, Reference + FeeTokenID=0 + FeeLimit=0 → V1 (ok)", | ||
| opts: &TransactOpts{FeeTokenID: 0, FeeLimit: big.NewInt(0), Reference: refTestPtr(ref)}, | ||
| wantVersion: types.MorphTxVersion1, | ||
| }, | ||
| { | ||
| name: "nil Version, Reference + FeeTokenID=0 + nil FeeLimit → V1 (ok)", | ||
| opts: &TransactOpts{FeeTokenID: 0, FeeLimit: nil, Reference: refTestPtr(ref)}, | ||
| wantVersion: types.MorphTxVersion1, | ||
| }, | ||
|
|
||
| // === Explicit Version === | ||
| { | ||
| name: "explicit V0, FeeTokenID > 0 → V0", | ||
| opts: &TransactOpts{Version: versionPtr(types.MorphTxVersion0), FeeTokenID: 1}, | ||
| wantVersion: types.MorphTxVersion0, | ||
| }, | ||
| { | ||
| name: "explicit V1, no special fields → V1", | ||
| opts: &TransactOpts{Version: versionPtr(types.MorphTxVersion1)}, | ||
| wantVersion: types.MorphTxVersion1, | ||
| }, | ||
| { | ||
| name: "explicit V1, with Reference + Memo → V1", | ||
| opts: &TransactOpts{Version: versionPtr(types.MorphTxVersion1), Reference: refTestPtr(ref), Memo: memoTestPtr(memo)}, | ||
| wantVersion: types.MorphTxVersion1, | ||
| }, | ||
| { | ||
| name: "explicit V0, FeeTokenID = 0 → error (V0 requires FeeTokenID > 0)", | ||
| opts: &TransactOpts{Version: versionPtr(types.MorphTxVersion0), FeeTokenID: 0}, | ||
| wantErr: types.ErrMorphTxV0IllegalExtraParams, | ||
| }, | ||
| { | ||
| name: "explicit V0, with Reference → error", | ||
| opts: &TransactOpts{Version: versionPtr(types.MorphTxVersion0), FeeTokenID: 1, Reference: refTestPtr(ref)}, | ||
| wantErr: types.ErrMorphTxV0IllegalExtraParams, | ||
| }, | ||
| { | ||
| name: "explicit V0, with Memo → error", | ||
| opts: &TransactOpts{Version: versionPtr(types.MorphTxVersion0), FeeTokenID: 1, Memo: memoTestPtr(memo)}, | ||
| wantErr: types.ErrMorphTxV0IllegalExtraParams, | ||
| }, | ||
| { | ||
| name: "explicit V1, FeeTokenID=0 + FeeLimit>0 → error", | ||
| opts: &TransactOpts{Version: versionPtr(types.MorphTxVersion1), FeeTokenID: 0, FeeLimit: big.NewInt(100)}, | ||
| wantErr: types.ErrMorphTxV1IllegalExtraParams, | ||
| }, | ||
| { | ||
| name: "unsupported version 255 → error", | ||
| opts: &TransactOpts{Version: versionPtr(255)}, | ||
| wantErr: types.ErrMorphTxUnsupportedVersion, | ||
| }, | ||
|
|
||
| // === Memo length validation === | ||
| { | ||
| name: "memo too long → error", | ||
| opts: &TransactOpts{FeeTokenID: 1, Memo: memoTestPtr(make([]byte, common.MaxMemoLength+1))}, | ||
| wantErr: types.ErrMemoTooLong, | ||
| }, | ||
| { | ||
| name: "memo at max length → ok", | ||
| opts: &TransactOpts{FeeTokenID: 1, Memo: memoTestPtr(make([]byte, common.MaxMemoLength))}, | ||
| wantVersion: types.MorphTxVersion1, // non-empty memo → V1 | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| version, err := bc.morphTxVersion(tt.opts) | ||
| if tt.wantErr != nil { | ||
| if err != tt.wantErr { | ||
| t.Errorf("error: got %v, want %v", err, tt.wantErr) | ||
| } | ||
| return | ||
| } | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if version != tt.wantVersion { | ||
| t.Errorf("version: got %d, want %d", version, tt.wantVersion) | ||
| } | ||
| }) | ||
| } | ||
| } |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.