|
| 1 | +package sequences_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "math/big" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/ethereum/go-ethereum/common" |
| 8 | + evm_contract "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/utils/operations/contract" |
| 9 | + "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_5_0/operations/token_admin_registry" |
| 10 | + "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_5_0/sequences" |
| 11 | + "github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_5_1/burn_mint_token_pool" |
| 12 | + "github.com/smartcontractkit/chainlink-deployments-framework/deployment" |
| 13 | + "github.com/smartcontractkit/chainlink-deployments-framework/engine/test/environment" |
| 14 | + "github.com/smartcontractkit/chainlink-deployments-framework/operations" |
| 15 | + "github.com/smartcontractkit/chainlink-evm/gethwrappers/shared/generated/initial/burn_mint_erc20" |
| 16 | + "github.com/stretchr/testify/require" |
| 17 | +) |
| 18 | + |
| 19 | +func TestRegisterToken(t *testing.T) { |
| 20 | + tests := []struct { |
| 21 | + desc string |
| 22 | + makeInput func(chainSel uint64, tokenAddress, tokenPoolAddress, tokenAdminRegistryAddress common.Address) sequences.RegisterTokenInput |
| 23 | + expectedErr string |
| 24 | + }{ |
| 25 | + { |
| 26 | + desc: "happy path - no external admin", |
| 27 | + makeInput: func(chainSel uint64, tokenAddress, tokenPoolAddress, tokenAdminRegistryAddress common.Address) sequences.RegisterTokenInput { |
| 28 | + return sequences.RegisterTokenInput{ |
| 29 | + ChainSelector: chainSel, |
| 30 | + TokenAddress: tokenAddress, |
| 31 | + TokenPoolAddress: tokenPoolAddress, |
| 32 | + ExternalAdmin: common.Address{}, |
| 33 | + TokenAdminRegistryAddress: tokenAdminRegistryAddress, |
| 34 | + } |
| 35 | + }, |
| 36 | + expectedErr: "", |
| 37 | + }, |
| 38 | + { |
| 39 | + desc: "happy path - external admin", |
| 40 | + makeInput: func(chainSel uint64, tokenAddress, tokenPoolAddress, tokenAdminRegistryAddress common.Address) sequences.RegisterTokenInput { |
| 41 | + return sequences.RegisterTokenInput{ |
| 42 | + ChainSelector: chainSel, |
| 43 | + TokenAddress: tokenAddress, |
| 44 | + TokenPoolAddress: tokenPoolAddress, |
| 45 | + ExternalAdmin: common.HexToAddress("0x07"), |
| 46 | + TokenAdminRegistryAddress: tokenAdminRegistryAddress, |
| 47 | + } |
| 48 | + }, |
| 49 | + expectedErr: "", |
| 50 | + }, |
| 51 | + } |
| 52 | + |
| 53 | + for _, test := range tests { |
| 54 | + t.Run(test.desc, func(t *testing.T) { |
| 55 | + chainSel := uint64(5009297550715157269) |
| 56 | + e, err := environment.New(t.Context(), |
| 57 | + environment.WithEVMSimulated(t, []uint64{chainSel}), |
| 58 | + ) |
| 59 | + require.NoError(t, err, "Failed to create environment") |
| 60 | + require.NotNil(t, e, "Environment should be created") |
| 61 | + |
| 62 | + // Deploy token admin registry |
| 63 | + tokenAdminRegistryReport, err := operations.ExecuteOperation( |
| 64 | + e.OperationsBundle, |
| 65 | + token_admin_registry.Deploy, |
| 66 | + e.BlockChains.EVMChains()[chainSel], |
| 67 | + evm_contract.DeployInput[token_admin_registry.ConstructorArgs]{ |
| 68 | + ChainSelector: chainSel, |
| 69 | + TypeAndVersion: deployment.NewTypeAndVersion(token_admin_registry.ContractType, *token_admin_registry.Version), |
| 70 | + }, |
| 71 | + ) |
| 72 | + require.NoError(t, err, "ExecuteOperation should not error") |
| 73 | + tokenAdminRegistryAddress := common.HexToAddress(tokenAdminRegistryReport.Output.Address) |
| 74 | + |
| 75 | + // Deploy token |
| 76 | + tokenAddress, tx, _, err := burn_mint_erc20.DeployBurnMintERC20( |
| 77 | + e.BlockChains.EVMChains()[chainSel].DeployerKey, |
| 78 | + e.BlockChains.EVMChains()[chainSel].Client, |
| 79 | + "Test Token", |
| 80 | + "TEST", |
| 81 | + 18, |
| 82 | + big.NewInt(1000000000000000000), |
| 83 | + big.NewInt(0), |
| 84 | + ) |
| 85 | + require.NoError(t, err, "DeployBurnMintERC20 should not error") |
| 86 | + _, err = e.BlockChains.EVMChains()[chainSel].Confirm(tx) |
| 87 | + require.NoError(t, err, "Confirm should not error") |
| 88 | + |
| 89 | + // Deploy token pool |
| 90 | + tokenPoolAddress, _, _, err := burn_mint_token_pool.DeployBurnMintTokenPool( |
| 91 | + e.BlockChains.EVMChains()[chainSel].DeployerKey, |
| 92 | + e.BlockChains.EVMChains()[chainSel].Client, |
| 93 | + tokenAddress, |
| 94 | + 18, |
| 95 | + []common.Address{}, |
| 96 | + common.HexToAddress("0x01"), |
| 97 | + common.HexToAddress("0x02"), |
| 98 | + ) |
| 99 | + require.NoError(t, err, "DeployBurnMintTokenPool should not error") |
| 100 | + |
| 101 | + input := test.makeInput( |
| 102 | + chainSel, |
| 103 | + tokenAddress, |
| 104 | + tokenPoolAddress, |
| 105 | + tokenAdminRegistryAddress, |
| 106 | + ) |
| 107 | + _, err = operations.ExecuteSequence( |
| 108 | + e.OperationsBundle, |
| 109 | + sequences.RegisterToken, |
| 110 | + e.BlockChains.EVMChains()[chainSel], |
| 111 | + input, |
| 112 | + ) |
| 113 | + if test.expectedErr != "" { |
| 114 | + require.Error(t, err, "ExecuteSequence should error") |
| 115 | + require.Contains(t, err.Error(), test.expectedErr) |
| 116 | + return |
| 117 | + } |
| 118 | + require.NoError(t, err, "ExecuteSequence should not error") |
| 119 | + |
| 120 | + // Checks |
| 121 | + tokenConfigReport, err := operations.ExecuteOperation( |
| 122 | + operations.NewBundle( |
| 123 | + e.OperationsBundle.GetContext, |
| 124 | + e.OperationsBundle.Logger, |
| 125 | + operations.NewMemoryReporter(), |
| 126 | + ), |
| 127 | + token_admin_registry.GetTokenConfig, |
| 128 | + e.BlockChains.EVMChains()[chainSel], |
| 129 | + evm_contract.FunctionInput[common.Address]{ |
| 130 | + ChainSelector: chainSel, |
| 131 | + Address: tokenAdminRegistryAddress, |
| 132 | + Args: tokenAddress, |
| 133 | + }, |
| 134 | + ) |
| 135 | + require.NoError(t, err, "ExecuteOperation should not error") |
| 136 | + if input.ExternalAdmin != (common.Address{}) { |
| 137 | + // We can propose an external admin, but we can't accept ownership or set the pool address since we don't control the admin. |
| 138 | + require.Equal(t, input.ExternalAdmin, tokenConfigReport.Output.PendingAdministrator) |
| 139 | + require.Equal(t, (common.Address{}), tokenConfigReport.Output.Administrator) |
| 140 | + require.Equal(t, (common.Address{}), tokenConfigReport.Output.TokenPool) |
| 141 | + } else { |
| 142 | + // No external admin means that the owner of the token admin registry will be proposed as the admin. |
| 143 | + // Since the deployer key is the owner of the token admin registry, it can accept admin rights and set the pool address. |
| 144 | + require.Equal(t, (common.Address{}), tokenConfigReport.Output.PendingAdministrator) |
| 145 | + require.Equal(t, e.BlockChains.EVMChains()[chainSel].DeployerKey.From, tokenConfigReport.Output.Administrator) |
| 146 | + require.Equal(t, input.TokenPoolAddress, tokenConfigReport.Output.TokenPool) |
| 147 | + } |
| 148 | + }) |
| 149 | + } |
| 150 | +} |
0 commit comments