-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[DPA-1313]: feat(deployment): add link contract deployment #15379
Merged
Merged
Changes from all commits
Commits
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 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 changeset | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/logger" | ||
|
||
"github.com/smartcontractkit/chainlink/deployment" | ||
"github.com/smartcontractkit/chainlink/deployment/common/types" | ||
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/link_token" | ||
) | ||
|
||
var _ deployment.ChangeSet[uint64] = DeployLinkToken | ||
|
||
// DeployLinkToken deploys a link token contract to the chain identified by the chainSelector. | ||
func DeployLinkToken(e deployment.Environment, chainSelector uint64) (deployment.ChangesetOutput, error) { | ||
c, ok := e.Chains[chainSelector] | ||
if !ok { | ||
return deployment.ChangesetOutput{}, fmt.Errorf("chain not found in environment") | ||
} | ||
newAddresses := deployment.NewMemoryAddressBook() | ||
_, err := deployLinkTokenContract( | ||
e.Logger, c, newAddresses, | ||
) | ||
if err != nil { | ||
return deployment.ChangesetOutput{AddressBook: newAddresses}, err | ||
} | ||
return deployment.ChangesetOutput{AddressBook: newAddresses}, nil | ||
} | ||
|
||
func deployLinkTokenContract( | ||
lggr logger.Logger, | ||
chain deployment.Chain, | ||
ab deployment.AddressBook, | ||
) (*deployment.ContractDeploy[*link_token.LinkToken], error) { | ||
linkToken, err := deployment.DeployContract[*link_token.LinkToken](lggr, chain, ab, | ||
func(chain deployment.Chain) deployment.ContractDeploy[*link_token.LinkToken] { | ||
linkTokenAddr, tx, linkToken, err2 := link_token.DeployLinkToken( | ||
chain.DeployerKey, | ||
chain.Client, | ||
) | ||
return deployment.ContractDeploy[*link_token.LinkToken]{ | ||
Address: linkTokenAddr, | ||
Contract: linkToken, | ||
Tx: tx, | ||
Tv: deployment.NewTypeAndVersion(types.LinkToken, deployment.Version1_0_0), | ||
Err: err2, | ||
} | ||
}) | ||
if err != nil { | ||
lggr.Errorw("Failed to deploy link token", "err", err) | ||
return linkToken, err | ||
} | ||
return linkToken, nil | ||
} |
This file contains 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,39 @@ | ||
package changeset_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/logger" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap/zapcore" | ||
|
||
"github.com/smartcontractkit/chainlink/deployment/common/changeset" | ||
"github.com/smartcontractkit/chainlink/deployment/environment/memory" | ||
) | ||
|
||
func TestDeployLinkToken(t *testing.T) { | ||
t.Parallel() | ||
|
||
lggr := logger.Test(t) | ||
cfg := memory.MemoryEnvironmentConfig{ | ||
Nodes: 1, | ||
Chains: 2, | ||
} | ||
env := memory.NewMemoryEnvironment(t, lggr, zapcore.DebugLevel, cfg) | ||
chainSelector := env.AllChainSelectors()[0] | ||
|
||
resp, err := changeset.DeployLinkToken(env, chainSelector) | ||
require.NoError(t, err) | ||
require.NotNil(t, resp) | ||
|
||
// LinkToken should be deployed on chain 0 | ||
addrs, err := resp.AddressBook.AddressesForChain(chainSelector) | ||
require.NoError(t, err) | ||
require.Len(t, addrs, 1) | ||
|
||
// nothing on chain 1 | ||
require.NotEqual(t, chainSelector, env.AllChainSelectors()[1]) | ||
oaddrs, _ := resp.AddressBook.AddressesForChain(env.AllChainSelectors()[1]) | ||
assert.Len(t, oaddrs, 0) | ||
} |
This file contains 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.
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.
This is not a criticism of you but I really hate that we have a function which returns a result, but also has a side-effect of updating a supplied address-book. :/ That's a sort of mis-matched use of function and side effect I'm not happy with. Need to rethink it.
You're doing it right, here, I think.
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.
Is the link deployment needed for test environments? If not, can we not use already deployed link contracts in various chains?
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 to know! I was kind of following the establish pattern here as seen in the code.
My understanding is that this changeset will be used for future new chains as well? And we are building a common bunch of useful changesets?
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.
Are we sure that this is the contract we can officially use as link contract for new chains? I was under impression this is just a test equivalent.
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.
If this is the intended one, please ignore me
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.
Yeah - established patterns aren't all "Good" yet. We have been evolving this under deadline pressure, so we're just now coming back to re-evaluate emerging patterns. You're not doing bad here, it's more you're echoing something that I need to rethink.
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.
@AnieeG thanks, let me double check with someone to be sure
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.
@AnieeG i doubled checked with Rodrigo, yes this is the one to use.