Skip to content
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

offchain - unit testing improvements #117

Merged
merged 31 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
97a0e6a
init and re-write commit observation
dimkouv Sep 5, 2023
8cc66b3
fix commit report phase
dimkouv Sep 5, 2023
45919b1
fix commit report encoding test
dimkouv Sep 6, 2023
2dc608b
remove non-plugin test from plugin test suite
dimkouv Sep 6, 2023
cfaa333
cleanup commit shouldTransmit test
dimkouv Sep 6, 2023
918a932
test commit shouldAccept phase, remove commit test harness
dimkouv Sep 6, 2023
2c675f3
test/refactor exec buildReport
dimkouv Sep 6, 2023
7c53799
test exec report to eth tx meta
dimkouv Sep 6, 2023
6841023
fix commit report tests
dimkouv Sep 6, 2023
8c88c80
write remaining tests for exec plugin + delete test harness
dimkouv Sep 6, 2023
8f6e74c
fix linter error
dimkouv Sep 6, 2023
42555e7
TestCommitReportingPlugin_calculateMinMaxSequenceNumbers
dimkouv Sep 7, 2023
5336c63
test get latest price updates
dimkouv Sep 7, 2023
06401eb
rename commit tests
dimkouv Sep 7, 2023
3cbcf56
rename and reorder exec plugin tests
dimkouv Sep 7, 2023
e3990d9
test remaining exec plugin methods
dimkouv Sep 7, 2023
7d525b0
Merge branch 'ccip-develop' into ref/improve-test-suite
dimkouv Sep 7, 2023
61a11ce
update wait for healthy postgres script
dimkouv Sep 8, 2023
9d0db6b
Merge branch 'chore/fix-wait-for-pg-script' into ref/improve-test-suite
dimkouv Sep 8, 2023
10e2029
fix failing test
dimkouv Sep 8, 2023
31195b8
merge from ccip-develop
dimkouv Sep 14, 2023
003873b
resolve linter errors
dimkouv Sep 14, 2023
4f0f91f
gitignore vendor dir
dimkouv Sep 14, 2023
c0279a1
improve test
dimkouv Sep 14, 2023
e22e298
assert no err
dimkouv Sep 14, 2023
71f3437
rename ccipevents.Client to ccipdata.Reader
dimkouv Sep 15, 2023
fadf7d3
Merge branch 'ccip-develop' into ref/improve-test-suite
dimkouv Sep 15, 2023
e754fe5
add fake implementations
dimkouv Sep 18, 2023
9cfd91c
Merge branch 'ref/improve-test-suite' of github.com:smartcontractkit/…
dimkouv Sep 18, 2023
cc1eec5
merge from ccip-develop
dimkouv Sep 18, 2023
008782c
rename 'events' to 'reader'
dimkouv Sep 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,5 @@ contracts/yarn.lock
/core/scripts/ccip/json/credentials
/core/scripts/ccip/revert-reason/bin/ccip-revert-reason

# dependencies generated after running `go mod vendor`
vendor/
28 changes: 28 additions & 0 deletions core/services/ocr2/plugins/ccip/abihelpers/abi_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import (
"fmt"
"math"
"math/big"
"math/rand"
"testing"

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/commit_store"
"github.com/smartcontractkit/chainlink/v2/core/utils"

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"
"github.com/test-go/testify/require"
Expand Down Expand Up @@ -58,6 +62,30 @@ func TestProofFlagToBits(t *testing.T) {
}
}

func TestCommitReportEncoding(t *testing.T) {
dimkouv marked this conversation as resolved.
Show resolved Hide resolved
report := commit_store.CommitStoreCommitReport{
PriceUpdates: commit_store.InternalPriceUpdates{
TokenPriceUpdates: []commit_store.InternalTokenPriceUpdate{
{
SourceToken: utils.RandomAddress(),
UsdPerToken: big.NewInt(9e18),
},
},
DestChainSelector: rand.Uint64(),
UsdPerUnitGas: big.NewInt(2000e9),
},
MerkleRoot: [32]byte{123},
Interval: commit_store.CommitStoreInterval{Min: 1, Max: 10},
}

encodedReport, err := EncodeCommitReport(report)
require.NoError(t, err)

decodedReport, err := DecodeCommitReport(encodedReport)
require.NoError(t, err)
require.Equal(t, report, decodedReport)
}

func TestExecutionReportEncoding(t *testing.T) {
// Note could consider some fancier testing here (fuzz/property)
// but I think that would essentially be testing geth's abi library
Expand Down
6 changes: 3 additions & 3 deletions core/services/ocr2/plugins/ccip/commit_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
libocr2 "github.com/smartcontractkit/libocr/offchainreporting2plus"

relaylogger "github.com/smartcontractkit/chainlink-relay/pkg/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipevents"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/hashlib"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/oraclelib"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/pricegetter"
Expand Down Expand Up @@ -106,8 +106,8 @@ func NewCommitServices(lggr logger.Logger, jb job.Job, chainSet evm.LegacyChainC
lggr: commitLggr,
sourceLP: sourceChain.LogPoller(),
destLP: destChain.LogPoller(),
sourceEvents: ccipevents.NewLogPollerClient(sourceChain.LogPoller(), commitLggr, sourceChain.Client()),
destEvents: ccipevents.NewLogPollerClient(destChain.LogPoller(), commitLggr, destChain.Client()),
sourceReader: ccipdata.NewLogPollerReader(sourceChain.LogPoller(), commitLggr, sourceChain.Client()),
destReader: ccipdata.NewLogPollerReader(destChain.LogPoller(), commitLggr, destChain.Client()),
offRamp: offRamp,
onRampAddress: onRamp.Address(),
priceGetter: priceGetterObject,
Expand Down
12 changes: 5 additions & 7 deletions core/services/ocr2/plugins/ccip/commit_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/commit_store"
mock_contracts "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/testhelpers"
)

func TestGetCommitPluginFilterNamesFromSpec(t *testing.T) {
Expand Down Expand Up @@ -87,13 +88,10 @@ func TestGetCommitPluginFilterNames(t *testing.T) {
onRampAddr := common.HexToAddress("0xdafea492d9c6733ae3d56b7ed1adb60692c98bc2")
priceRegAddr := common.HexToAddress("0xdafea492d9c6733ae3d56b7ed1adb60692c98bc3")
offRampAddr := common.HexToAddress("0xDAFeA492D9c6733Ae3D56b7eD1AdB60692C98BC4")
mockCommitStore := mock_contracts.NewCommitStoreInterface(t)
mockCommitStore.On("GetStaticConfig", mock.Anything).Return(commit_store.CommitStoreStaticConfig{
OnRamp: onRampAddr,
}, nil)
mockCommitStore.On("GetDynamicConfig", mock.Anything).Return(commit_store.CommitStoreDynamicConfig{
PriceRegistry: priceRegAddr,
}, nil)

mockCommitStore, _ := testhelpers.NewFakeCommitStore(t, 1)
mockCommitStore.SetStaticConfig(commit_store.CommitStoreStaticConfig{OnRamp: onRampAddr})
mockCommitStore.SetDynamicConfig(commit_store.CommitStoreDynamicConfig{PriceRegistry: priceRegAddr})

srcLP := mocklp.NewLogPoller(t)
dstLP := mocklp.NewLogPoller(t)
Expand Down
14 changes: 7 additions & 7 deletions core/services/ocr2/plugins/ccip/commit_reporting_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/abihelpers"
ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/pricegetter"

"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/cache"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipevents"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/hashlib"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/merklemulti"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
Expand Down Expand Up @@ -56,8 +56,8 @@ type update struct {
type CommitPluginConfig struct {
lggr logger.Logger
sourceLP, destLP logpoller.LogPoller
sourceEvents ccipevents.Client
destEvents ccipevents.Client
sourceReader ccipdata.Reader
destReader ccipdata.Reader
offRamp evm_2_evm_offramp.EVM2EVMOffRampInterface
onRampAddress common.Address
commitStore commit_store.CommitStoreInterface
Expand Down Expand Up @@ -238,7 +238,7 @@ func (r *CommitReportingPlugin) calculateMinMaxSequenceNumbers(ctx context.Conte
return 0, 0, err
}

msgRequests, err := r.config.sourceEvents.GetSendRequestsGteSeqNum(ctx, r.config.onRampAddress, nextInflightMin, r.config.checkFinalityTags, int(r.offchainConfig.SourceFinalityDepth))
msgRequests, err := r.config.sourceReader.GetSendRequestsGteSeqNum(ctx, r.config.onRampAddress, nextInflightMin, r.config.checkFinalityTags, int(r.offchainConfig.SourceFinalityDepth))
if err != nil {
return 0, 0, err
}
Expand Down Expand Up @@ -367,7 +367,7 @@ func calculateUsdPer1e18TokenAmount(price *big.Int, decimals uint8) *big.Int {
// Gets the latest token price updates based on logs within the heartbeat
// The updates returned by this function are guaranteed to not contain nil values.
func (r *CommitReportingPlugin) getLatestTokenPriceUpdates(ctx context.Context, now time.Time, checkInflight bool) (map[common.Address]update, error) {
tokenPriceUpdates, err := r.config.destEvents.GetTokenPriceUpdatesCreatedAfter(
tokenPriceUpdates, err := r.config.destReader.GetTokenPriceUpdatesCreatedAfter(
ctx,
r.destPriceRegistry.Address(),
now.Add(-r.offchainConfig.FeeUpdateHeartBeat.Duration()),
Expand Down Expand Up @@ -423,7 +423,7 @@ func (r *CommitReportingPlugin) getLatestGasPriceUpdate(ctx context.Context, now
}

// If there are no price updates inflight, check latest prices onchain
gasPriceUpdates, err := r.config.destEvents.GetGasPriceUpdatesCreatedAfter(
gasPriceUpdates, err := r.config.destReader.GetGasPriceUpdatesCreatedAfter(
ctx,
r.destPriceRegistry.Address(),
r.config.sourceChainSelector,
Expand Down Expand Up @@ -657,7 +657,7 @@ func (r *CommitReportingPlugin) buildReport(ctx context.Context, lggr logger.Log

// Logs are guaranteed to be in order of seq num, since these are finalized logs only
// and the contract's seq num is auto-incrementing.
sendRequests, err := r.config.sourceEvents.GetSendRequestsBetweenSeqNums(
sendRequests, err := r.config.sourceReader.GetSendRequestsBetweenSeqNums(
ctx,
r.config.onRampAddress,
interval.Min,
Expand Down
Loading
Loading