Skip to content

Commit

Permalink
Add tests for Celo2 Signer compatibility with both Celo1 and Celo2 tr…
Browse files Browse the repository at this point in the history
…ansactions (#308)

* Fix typo

* Add unit tests for forks

* Add unit tests for Celo signer

* Format code

* Simplify Test_forks_activeForks and Test_forks_findTxFuncs

* Remove Test_forks_findTxFuncs
  • Loading branch information
Kourin1996 authored Jan 24, 2025
1 parent 5df6a68 commit 461d643
Show file tree
Hide file tree
Showing 3 changed files with 486 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/types/celo_transaction_signing_forks.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ func (c *celoLegacy) txFuncs(tx *Transaction) *txFuncs {
return celoLegacyTxFuncs
case t == DynamicFeeTxType:
// We handle the dynamic fee tx type here because we need to handle
// migrated dynamic fee txs. These were enabeled in celo in the Espresso
// migrated dynamic fee txs. These were enabled in celo in the Espresso
// hardfork, which doesn't have any analogue in op-geth. Even though
// op-geth does enable support for dynamic fee txs in the London
// hardfork (which we set to the cel2 block) that fork contains a lot of
// changes that were not part of Espresso. So instead we ned to handle
// changes that were not part of Espresso. So instead we need to handle
// DynamicFeeTxTypes here.
return dynamicFeeTxFuncs
case t == AccessListTxType:
Expand Down
36 changes: 36 additions & 0 deletions core/types/celo_transaction_signing_forks_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package types

import (
"testing"

"github.com/ethereum/go-ethereum/params"
"github.com/stretchr/testify/assert"
)

// Test_forks_activeForks tests that the correct forks are returned for a given block time and chain config
func Test_forks_activeForks(t *testing.T) {
t.Parallel()

cel2Time := uint64(1000)

t.Run("Non-Celo", func(t *testing.T) {
config := &params.ChainConfig{
Cel2Time: nil,
}
assert.Equal(t, []fork(nil), celoForks.activeForks(1000, config))
})

t.Run("Celo1", func(t *testing.T) {
config := &params.ChainConfig{
Cel2Time: &cel2Time,
}
assert.Equal(t, []fork{&celoLegacy{}}, celoForks.activeForks(500, config))
})

t.Run("Celo2", func(t *testing.T) {
config := &params.ChainConfig{
Cel2Time: &cel2Time,
}
assert.Equal(t, []fork{&cel2{}, &celoLegacy{}}, celoForks.activeForks(1000, config))
})
}
Loading

0 comments on commit 461d643

Please sign in to comment.