Skip to content

Commit 4ce2d7a

Browse files
feat(sui): add support for contract upgrades (#480)
## Description Add support for upgrading Sui contracts (and the corresponding e2e tests). --------- Co-authored-by: RodrigoAD <15104916+RodrigoAD@users.noreply.github.com>
1 parent aabbb32 commit 4ce2d7a

19 files changed

+2264
-199
lines changed

.changeset/sweet-steaks-study.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smartcontractkit/mcms": minor
3+
---
4+
5+
add support for Sui contract upgrades operations

.mockery.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ packages:
128128
config:
129129
dir: "./sdk/sui/mocks/feequoter"
130130
filename: "feequoterencoder.go"
131+
github.com/smartcontractkit/chainlink-sui/bindings/generated/mcms/mcms_deployer:
132+
config:
133+
all: false
134+
outpkg: "mock_module_mcmsdeployer"
135+
interfaces:
136+
IMcmsDeployer:
137+
config:
138+
dir: "./sdk/sui/mocks/mcmsdeployer"
139+
filename: "imcmsdeployer.go"
140+
McmsDeployerEncoder:
141+
config:
142+
dir: "./sdk/sui/mocks/mcmsdeployer"
143+
filename: "mcmsdeployerencoder.go"
131144

132145
# Required to fix the following deprecation warning:
133146
# https://vektra.github.io/mockery/v2.48/deprecations/#issue-845-fix

e2e/tests/runner_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ func TestSuiSuite(t *testing.T) {
3838
suite.Run(t, new(suie2e.SetRootTestSuite))
3939
suite.Run(t, new(suie2e.MCMSUserTestSuite))
4040
suite.Run(t, new(suie2e.TimelockCancelProposalTestSuite))
41+
suite.Run(t, new(suie2e.MCMSUserUpgradeTestSuite))
4142
}

e2e/tests/setup.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ type Config struct {
4141
SuiChain *blockchain.Input `toml:"sui_config"`
4242

4343
Settings struct {
44-
PrivateKeys []string `toml:"private_keys"`
44+
PrivateKeys []string `toml:"private_keys"`
45+
LocalSuiNodeURL string `toml:"local_sui_node_url,omitempty"`
4546
} `toml:"settings"`
4647
}
4748

@@ -180,7 +181,12 @@ func InitializeSharedTestSetup(t *testing.T) *TestSetup {
180181
suiClient sui.ISuiAPI
181182
suiBlockchainOutput *blockchain.Output
182183
)
183-
if in.SuiChain != nil {
184+
if in.Settings.LocalSuiNodeURL != "" {
185+
// Connect to local Sui node (highest priority)
186+
suiClient = sui.NewSuiClient(in.Settings.LocalSuiNodeURL)
187+
t.Logf("Connected to local Sui node @ %s", in.Settings.LocalSuiNodeURL)
188+
} else if in.SuiChain != nil {
189+
// Use blockchain network setup (fallback)
184190
ports := freeport.GetN(t, 2)
185191
port := ports[0]
186192
faucetPort := ports[1]

e2e/tests/sui/common.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ type SuiTestSuite struct {
4848
mcmsAccount modulemcmsaccount.IMcmsAccount
4949

5050
// MCMS User
51-
mcmsUserPackageId string
52-
mcmsUser modulemcmsuser.IMcmsUser
53-
mcmsUserOwnerCapObj string
51+
mcmsUserPackageID string
52+
mcmsUser modulemcmsuser.IMcmsUser
53+
mcmsUserOwnerCapObj string
54+
mcmsUserUpgradeCapObj string
5455

5556
// State Object passed into `mcms_entrypoint`
5657
stateObj string
@@ -131,16 +132,19 @@ func (s *SuiTestSuite) DeployMCMSUserContract() {
131132
}, s.client, s.mcmsPackageID, signerAddress)
132133
s.Require().NoError(err, "Failed to publish MCMS user package")
133134

134-
s.mcmsUserPackageId = mcmsUserPackage.Address()
135+
s.mcmsUserPackageID = mcmsUserPackage.Address()
135136
s.mcmsUser = mcmsUserPackage.MCMSUser()
136137

137138
userDataObj, err := bind.FindObjectIdFromPublishTx(*tx, "mcms_user", "UserData")
138139
s.Require().NoError(err, "Failed to find object IDs in publish tx")
139-
mcmsUserOwnerCapObj, err := bind.FindObjectIdFromPublishTx(*tx, "mcms_user", "OwnerCap")
140+
mcmsUserOwnerCapObj, err := bind.FindObjectIdFromPublishTx(*tx, "ownable", "OwnerCap")
141+
s.Require().NoError(err, "Failed to find object IDs in publish tx")
142+
mcmsUserUpgradeCapObj, err := bind.FindObjectIdFromPublishTx(*tx, "package", "UpgradeCap")
140143
s.Require().NoError(err, "Failed to find object IDs in publish tx")
141144

142145
s.mcmsUserOwnerCapObj = mcmsUserOwnerCapObj
143146
s.stateObj = userDataObj
147+
s.mcmsUserUpgradeCapObj = mcmsUserUpgradeCapObj
144148

145149
// For executing, We need to register OwnerCap with MCMS
146150
{
@@ -181,8 +185,8 @@ type TestEntrypointArgEncoder struct {
181185
}
182186

183187
func (e *TestEntrypointArgEncoder) EncodeEntryPointArg(executingCallbackParams *transaction.Argument, target, module, function, stateObjID string, data []byte) (*bind.EncodedCall, error) {
184-
// For simplicity, we only support MCMSUser as target in this test encoder
185-
if module != "MCMSUser" {
188+
// For simplicity, we only support mcms_user as target in this test encoder
189+
if module != "mcms_user" {
186190
return nil, fmt.Errorf("unsupported module: %s", module)
187191
}
188192
mcmsUser, err := mcmsuser.NewMCMSUser(target, e.client)

0 commit comments

Comments
 (0)