-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathaccept_ownership_test.go
126 lines (110 loc) · 3.94 KB
/
accept_ownership_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package changeset
import (
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"
commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset"
"github.com/smartcontractkit/chainlink/deployment/common/proposalutils"
)
func Test_NewAcceptOwnershipChangeset(t *testing.T) {
t.Parallel()
e, _ := NewMemoryEnvironment(t)
state, err := LoadOnchainState(e.Env)
require.NoError(t, err)
allChains := maps.Keys(e.Env.Chains)
source := allChains[0]
dest := allChains[1]
timelockContracts := map[uint64]*proposalutils.TimelockExecutionContracts{
source: {
Timelock: state.Chains[source].Timelock,
CallProxy: state.Chains[source].CallProxy,
},
dest: {
Timelock: state.Chains[dest].Timelock,
CallProxy: state.Chains[dest].CallProxy,
},
}
// at this point we have the initial deploys done, now we need to transfer ownership
// to the timelock contract
state, err = LoadOnchainState(e.Env)
require.NoError(t, err)
// compose the transfer ownership and accept ownership changesets
_, err = commonchangeset.ApplyChangesets(t, e.Env, timelockContracts, []commonchangeset.ChangesetApplication{
// note this doesn't have proposals.
{
Changeset: commonchangeset.WrapChangeSet(commonchangeset.TransferToMCMSWithTimelock),
Config: genTestTransferOwnershipConfig(e, allChains, state),
},
})
require.NoError(t, err)
assertTimelockOwnership(t, e, allChains, state)
}
func genTestTransferOwnershipConfig(
e DeployedEnv,
chains []uint64,
state CCIPOnChainState,
) commonchangeset.TransferToMCMSWithTimelockConfig {
var (
timelocksPerChain = make(map[uint64]common.Address)
contracts = make(map[uint64][]common.Address)
)
// chain contracts
for _, chain := range chains {
timelocksPerChain[chain] = state.Chains[chain].Timelock.Address()
contracts[chain] = []common.Address{
state.Chains[chain].OnRamp.Address(),
state.Chains[chain].OffRamp.Address(),
state.Chains[chain].FeeQuoter.Address(),
state.Chains[chain].NonceManager.Address(),
state.Chains[chain].RMNRemote.Address(),
state.Chains[chain].TestRouter.Address(),
state.Chains[chain].Router.Address(),
}
}
// home chain
homeChainTimelockAddress := state.Chains[e.HomeChainSel].Timelock.Address()
timelocksPerChain[e.HomeChainSel] = homeChainTimelockAddress
contracts[e.HomeChainSel] = append(contracts[e.HomeChainSel],
state.Chains[e.HomeChainSel].CapabilityRegistry.Address(),
state.Chains[e.HomeChainSel].CCIPHome.Address(),
state.Chains[e.HomeChainSel].RMNHome.Address(),
)
return commonchangeset.TransferToMCMSWithTimelockConfig{
ContractsByChain: contracts,
}
}
// assertTimelockOwnership asserts that the ownership of the contracts has been transferred
// to the appropriate timelock contract on each chain.
func assertTimelockOwnership(
t *testing.T,
e DeployedEnv,
chains []uint64,
state CCIPOnChainState,
) {
// check that the ownership has been transferred correctly
for _, chain := range chains {
for _, contract := range []common.Address{
state.Chains[chain].OnRamp.Address(),
state.Chains[chain].OffRamp.Address(),
state.Chains[chain].FeeQuoter.Address(),
state.Chains[chain].NonceManager.Address(),
state.Chains[chain].RMNRemote.Address(),
} {
owner, _, err := commonchangeset.LoadOwnableContract(contract, e.Env.Chains[chain].Client)
require.NoError(t, err)
require.Equal(t, state.Chains[chain].Timelock.Address(), owner)
}
}
// check home chain contracts ownership
homeChainTimelockAddress := state.Chains[e.HomeChainSel].Timelock.Address()
for _, contract := range []common.Address{
state.Chains[e.HomeChainSel].CapabilityRegistry.Address(),
state.Chains[e.HomeChainSel].CCIPHome.Address(),
state.Chains[e.HomeChainSel].RMNHome.Address(),
} {
owner, _, err := commonchangeset.LoadOwnableContract(contract, e.Env.Chains[e.HomeChainSel].Client)
require.NoError(t, err)
require.Equal(t, homeChainTimelockAddress, owner)
}
}