-
Notifications
You must be signed in to change notification settings - Fork 2
Canton2EVM devenv token transfer and validation tests #693
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
6 commits
Select commit
Hold shift + click to select a range
fe440c8
Canton2EVM devenv token transfer and validation tests
JohnChangUK 3bc4fd9
fix uint32 overflow checks in fee quoter limits
JohnChangUK b617ee6
Merge branch 'main' into validation-tests
JohnChangUK 62c6266
Reorder functions order
JohnChangUK a9b84eb
Merge branch 'main' into validation-tests
JohnChangUK 4f351b9
Merge branch 'main' into validation-tests
JohnChangUK 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| package devenv | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "math" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| apiv2 "github.com/digital-asset/dazl-client/v8/go/api/com/daml/ledger/api/v2" | ||
| "github.com/smartcontractkit/chainlink-deployments-framework/datastore" | ||
| "github.com/smartcontractkit/go-daml/pkg/service/ledger" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-canton/bindings/generated/latest/ccip/core" | ||
| "github.com/smartcontractkit/chainlink-canton/contracts" | ||
| feequoterop "github.com/smartcontractkit/chainlink-canton/deployment/operations/ccip/fee_quoter" | ||
| "github.com/smartcontractkit/chainlink-canton/deployment/utils/operations/contract" | ||
| ) | ||
|
|
||
| // GetMaxDataBytes implements cciptestinterfaces.CCIP17. | ||
| func (c *Chain) GetMaxDataBytes(ctx context.Context, remoteChainSelector uint64) (uint32, error) { | ||
| cfg, err := c.feeQuoterDestConfig(ctx, remoteChainSelector) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
| if cfg.MaxDataBytes < 0 { | ||
| return 0, fmt.Errorf("negative maxDataBytes: %d", cfg.MaxDataBytes) | ||
| } | ||
| if cfg.MaxDataBytes > math.MaxUint32 { | ||
| return 0, fmt.Errorf("maxDataBytes overflows uint32: %d", cfg.MaxDataBytes) | ||
| } | ||
|
|
||
| return uint32(cfg.MaxDataBytes), nil | ||
| } | ||
|
|
||
| // GetMaxPerMsgGasLimit returns the FeeQuoter maxPerMsgGasLimit for a destination chain. | ||
| func (c *Chain) GetMaxPerMsgGasLimit(ctx context.Context, remoteChainSelector uint64) (uint32, error) { | ||
| cfg, err := c.feeQuoterDestConfig(ctx, remoteChainSelector) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
| if cfg.MaxPerMsgGasLimit < 0 { | ||
| return 0, fmt.Errorf("negative maxPerMsgGasLimit: %d", cfg.MaxPerMsgGasLimit) | ||
| } | ||
| if cfg.MaxPerMsgGasLimit > math.MaxUint32 { | ||
| return 0, fmt.Errorf("maxPerMsgGasLimit overflows uint32: %d", cfg.MaxPerMsgGasLimit) | ||
| } | ||
|
|
||
| return uint32(cfg.MaxPerMsgGasLimit), nil | ||
| } | ||
|
|
||
| func (c *Chain) feeQuoterDestConfig(ctx context.Context, remoteChainSelector uint64) (core.FeeQuoterDestChainConfig, error) { | ||
| if c.e == nil { | ||
| return core.FeeQuoterDestChainConfig{}, fmt.Errorf("canton chain environment is nil") | ||
| } | ||
| if len(c.chain.Participants) == 0 { | ||
| return core.FeeQuoterDestChainConfig{}, fmt.Errorf("no canton participants configured") | ||
| } | ||
|
|
||
| feeQuoterRef, err := c.e.DataStore.Addresses().Get(datastore.NewAddressRefKey( | ||
| c.ChainSelector(), | ||
| datastore.ContractType(feequoterop.ContractType), | ||
| feequoterop.Version, | ||
| "", | ||
| )) | ||
| if err != nil { | ||
| return core.FeeQuoterDestChainConfig{}, fmt.Errorf("resolve FeeQuoter address: %w", err) | ||
| } | ||
|
|
||
| participant := c.chain.Participants[0] | ||
| party := participant.PartyID | ||
| feeQuoterAddress := contracts.HexToInstanceAddress(feeQuoterRef.Address) | ||
|
|
||
| activeContract, err := contract.FindActiveContractByInstanceAddress( | ||
| ctx, | ||
| participant.LedgerServices.State, | ||
| []string{party}, | ||
| core.FeeQuoter{}.GetTemplateID(), | ||
| feeQuoterAddress, | ||
| ) | ||
| if err != nil { | ||
| return core.FeeQuoterDestChainConfig{}, fmt.Errorf("find active FeeQuoter contract: %w", err) | ||
| } | ||
|
|
||
| createArgs := activeContract.GetCreatedEvent().GetCreateArguments() | ||
| if createArgs == nil { | ||
| return core.FeeQuoterDestChainConfig{}, fmt.Errorf("FeeQuoter create arguments missing") | ||
| } | ||
|
|
||
| return destChainConfigFromFeeQuoterCreateArgs(createArgs, remoteChainSelector) | ||
| } | ||
|
|
||
| func destChainConfigFromFeeQuoterCreateArgs(createArgs *apiv2.Record, remoteChainSelector uint64) (core.FeeQuoterDestChainConfig, error) { | ||
| selectorKey := strconv.FormatUint(remoteChainSelector, 10) | ||
| for _, field := range createArgs.GetFields() { | ||
| if field.GetLabel() != "destChainConfigs" { | ||
| continue | ||
| } | ||
| genMap := field.GetValue().GetGenMap() | ||
| if genMap == nil { | ||
| return core.FeeQuoterDestChainConfig{}, fmt.Errorf("destChainConfigs is not a GenMap") | ||
| } | ||
| for _, entry := range genMap.GetEntries() { | ||
| key := strings.TrimSuffix(entry.GetKey().GetNumeric(), ".") | ||
| if key != selectorKey { | ||
| continue | ||
| } | ||
| record := entry.GetValue().GetRecord() | ||
| if record == nil { | ||
| return core.FeeQuoterDestChainConfig{}, fmt.Errorf("dest chain config value is not a record") | ||
| } | ||
| var cfg core.FeeQuoterDestChainConfig | ||
| if err := ledger.RecordToStruct(record, &cfg); err != nil { | ||
| return core.FeeQuoterDestChainConfig{}, fmt.Errorf("parse dest chain config record: %w", err) | ||
| } | ||
|
|
||
| return cfg, nil | ||
| } | ||
|
|
||
| return core.FeeQuoterDestChainConfig{}, fmt.Errorf("no FeeQuoter dest config for chain selector %d", remoteChainSelector) | ||
| } | ||
|
|
||
| return core.FeeQuoterDestChainConfig{}, fmt.Errorf("destChainConfigs field not found on FeeQuoter") | ||
| } | ||
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,55 @@ | ||
| package devenv | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-canton/bindings/generated/latest/splice/splice_api_token_holding_v1" | ||
| "github.com/smartcontractkit/chainlink-canton/testhelpers" | ||
| ) | ||
|
|
||
| // ClearFeeHoldingForTest clears the next fee holding CID so SendMessage fails without a fee input. | ||
| func (c *Chain) ClearFeeHoldingForTest() { | ||
| c.nextFeeCID = "" | ||
| } | ||
|
|
||
| // SetNextFeeCIDForTest overrides the fee holding CID used on the next send. | ||
| func (c *Chain) SetNextFeeCIDForTest(cid string) { | ||
| c.nextFeeCID = cid | ||
| } | ||
|
|
||
| // MintTokensReturningCID mints Amulet and returns the new holding contract ID. | ||
| func (c *Chain) MintTokensReturningCID(ctx context.Context, amount string) (string, error) { | ||
| participant := c.chain.Participants[0] | ||
| party := participant.PartyID | ||
|
|
||
| validatorAPIClients, err := c.getValidatorAPIClients() | ||
| if err != nil { | ||
| return "", fmt.Errorf("get validator API clients: %w", err) | ||
| } | ||
|
|
||
| cid, err := testhelpers.MintAMT( | ||
| ctx, | ||
| participant, | ||
| validatorAPIClients.metadataClient, | ||
| validatorAPIClients.transferClient, | ||
| validatorAPIClients.scanClient, | ||
| party, | ||
| amount, | ||
| ) | ||
| if err != nil { | ||
| return "", fmt.Errorf("mint tokens: %w", err) | ||
| } | ||
|
|
||
| return cid, nil | ||
| } | ||
|
|
||
| // SetFeeTokenInstrumentForTest overrides the fee token instrument used on the next send. | ||
| func (c *Chain) SetFeeTokenInstrumentForTest(inst splice_api_token_holding_v1.InstrumentId) { | ||
| c.feeTokenInstrument = inst | ||
| } | ||
|
|
||
| // SetTransferTokenInstrumentForTest overrides the transfer token instrument used on the next send. | ||
| func (c *Chain) SetTransferTokenInstrumentForTest(inst splice_api_token_holding_v1.InstrumentId) { | ||
| c.transferTokenInstrument = &inst | ||
| } |
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.
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.
Thanks for creating another file and not putting this under impl.go
Could we order the functions definitions? As:
1 - Exported methods first
2 - Unexported methods
3 - Helper functions (eg: destChainConfigFromFeeQuoterCreateArgs)
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.
Addressed, thanks!