From 0d03fd40f6d330cbe4e2e05a0614f29136366bb6 Mon Sep 17 00:00:00 2001 From: dragosrebegea Date: Tue, 23 Jan 2024 19:44:52 +0200 Subject: [PATCH 1/3] MX-15083: fix mxClientDataGetter --- clients/multiversx/mxClientDataGetter.go | 46 ++++++----- clients/multiversx/mxClientDataGetter_test.go | 77 +++++++++++++++++++ cmd/bridge/config/config.toml | 1 + config/config.go | 1 + factory/ethMultiversXBridgeComponents.go | 7 ++ 5 files changed, 114 insertions(+), 18 deletions(-) diff --git a/clients/multiversx/mxClientDataGetter.go b/clients/multiversx/mxClientDataGetter.go index ed880ceb..e21fb255 100644 --- a/clients/multiversx/mxClientDataGetter.go +++ b/clients/multiversx/mxClientDataGetter.go @@ -40,6 +40,7 @@ const ( // ArgsMXClientDataGetter is the arguments DTO used in the NewMXClientDataGetter constructor type ArgsMXClientDataGetter struct { MultisigContractAddress core.AddressHandler + SafeContractAddress core.AddressHandler RelayerAddress core.AddressHandler Proxy Proxy Log logger.Logger @@ -47,6 +48,7 @@ type ArgsMXClientDataGetter struct { type mxClientDataGetter struct { multisigContractAddress core.AddressHandler + safeContractAddress core.AddressHandler bech32MultisigContractAddress string relayerAddress core.AddressHandler proxy Proxy @@ -70,6 +72,9 @@ func NewMXClientDataGetter(args ArgsMXClientDataGetter) (*mxClientDataGetter, er if check.IfNil(args.MultisigContractAddress) { return nil, fmt.Errorf("%w for the MultisigContractAddress argument", errNilAddressHandler) } + if check.IfNil(args.SafeContractAddress) { + return nil, fmt.Errorf("%w for the SafeContractAddress argument", errNilAddressHandler) + } bech32Address, err := args.MultisigContractAddress.AddressAsBech32String() if err != nil { return nil, fmt.Errorf("%w for %x", err, args.MultisigContractAddress.AddressBytes()) @@ -77,6 +82,7 @@ func NewMXClientDataGetter(args ArgsMXClientDataGetter) (*mxClientDataGetter, er return &mxClientDataGetter{ multisigContractAddress: args.MultisigContractAddress, + safeContractAddress: args.SafeContractAddress, bech32MultisigContractAddress: bech32Address, relayerAddress: args.RelayerAddress, proxy: args.Proxy, @@ -271,13 +277,17 @@ func (dataGetter *mxClientDataGetter) executeQueryBoolFromBuilder(ctx context.Co return dataGetter.ExecuteQueryReturningBool(ctx, vmValuesRequest) } -func (dataGetter *mxClientDataGetter) createDefaultVmQueryBuilder() builders.VMQueryBuilder { +func (dataGetter *mxClientDataGetter) createMultisigDefaultVmQueryBuilder() builders.VMQueryBuilder { return builders.NewVMQueryBuilder().Address(dataGetter.multisigContractAddress).CallerAddress(dataGetter.relayerAddress) } +func (dataGetter *mxClientDataGetter) createSafeDefaultVmQueryBuilder() builders.VMQueryBuilder { + return builders.NewVMQueryBuilder().Address(dataGetter.safeContractAddress).CallerAddress(dataGetter.relayerAddress) +} + // GetCurrentBatchAsDataBytes will assemble a builder and query the proxy for the current pending batch func (dataGetter *mxClientDataGetter) GetCurrentBatchAsDataBytes(ctx context.Context) ([][]byte, error) { - builder := dataGetter.createDefaultVmQueryBuilder() + builder := dataGetter.createMultisigDefaultVmQueryBuilder() builder.Function(getCurrentTxBatchFuncName) return dataGetter.executeQueryFromBuilder(ctx, builder) @@ -285,7 +295,7 @@ func (dataGetter *mxClientDataGetter) GetCurrentBatchAsDataBytes(ctx context.Con // GetTokenIdForErc20Address will assemble a builder and query the proxy for a token id given a specific erc20 address func (dataGetter *mxClientDataGetter) GetTokenIdForErc20Address(ctx context.Context, erc20Address []byte) ([][]byte, error) { - builder := dataGetter.createDefaultVmQueryBuilder() + builder := dataGetter.createMultisigDefaultVmQueryBuilder() builder.Function(getTokenIdForErc20AddressFuncName) builder.ArgBytes(erc20Address) @@ -294,7 +304,7 @@ func (dataGetter *mxClientDataGetter) GetTokenIdForErc20Address(ctx context.Cont // GetERC20AddressForTokenId will assemble a builder and query the proxy for an erc20 address given a specific token id func (dataGetter *mxClientDataGetter) GetERC20AddressForTokenId(ctx context.Context, tokenId []byte) ([][]byte, error) { - builder := dataGetter.createDefaultVmQueryBuilder() + builder := dataGetter.createMultisigDefaultVmQueryBuilder() builder.Function(getErc20AddressForTokenIdFuncName) builder.ArgBytes(tokenId) return dataGetter.executeQueryFromBuilder(ctx, builder) @@ -306,7 +316,7 @@ func (dataGetter *mxClientDataGetter) WasProposedTransfer(ctx context.Context, b return false, clients.ErrNilBatch } - builder := dataGetter.createDefaultVmQueryBuilder() + builder := dataGetter.createMultisigDefaultVmQueryBuilder() builder.Function(wasTransferActionProposedFuncName).ArgInt64(int64(batch.ID)) addBatchInfo(builder, batch) @@ -315,7 +325,7 @@ func (dataGetter *mxClientDataGetter) WasProposedTransfer(ctx context.Context, b // WasExecuted returns true if the provided actionID was executed or not func (dataGetter *mxClientDataGetter) WasExecuted(ctx context.Context, actionID uint64) (bool, error) { - builder := dataGetter.createDefaultVmQueryBuilder() + builder := dataGetter.createMultisigDefaultVmQueryBuilder() builder.Function(wasActionExecutedFuncName).ArgInt64(int64(actionID)) return dataGetter.executeQueryBoolFromBuilder(ctx, builder) @@ -327,7 +337,7 @@ func (dataGetter *mxClientDataGetter) GetActionIDForProposeTransfer(ctx context. return 0, clients.ErrNilBatch } - builder := dataGetter.createDefaultVmQueryBuilder() + builder := dataGetter.createMultisigDefaultVmQueryBuilder() builder.Function(getActionIdForTransferBatchFuncName).ArgInt64(int64(batch.ID)) addBatchInfo(builder, batch) @@ -340,7 +350,7 @@ func (dataGetter *mxClientDataGetter) WasProposedSetStatus(ctx context.Context, return false, clients.ErrNilBatch } - builder := dataGetter.createDefaultVmQueryBuilder() + builder := dataGetter.createMultisigDefaultVmQueryBuilder() builder.Function(wasSetCurrentTransactionBatchStatusActionProposedFuncName).ArgInt64(int64(batch.ID)) for _, stat := range batch.Statuses { builder.ArgBytes([]byte{stat}) @@ -351,7 +361,7 @@ func (dataGetter *mxClientDataGetter) WasProposedSetStatus(ctx context.Context, // GetTransactionsStatuses will return the transactions statuses from the batch ID func (dataGetter *mxClientDataGetter) GetTransactionsStatuses(ctx context.Context, batchID uint64) ([]byte, error) { - builder := dataGetter.createDefaultVmQueryBuilder() + builder := dataGetter.createMultisigDefaultVmQueryBuilder() builder.Function(getStatusesAfterExecutionFuncName).ArgInt64(int64(batchID)) values, err := dataGetter.executeQueryFromBuilder(ctx, builder) @@ -391,7 +401,7 @@ func (dataGetter *mxClientDataGetter) GetActionIDForSetStatusOnPendingTransfer(c return 0, clients.ErrNilBatch } - builder := dataGetter.createDefaultVmQueryBuilder() + builder := dataGetter.createMultisigDefaultVmQueryBuilder() builder.Function(getActionIdForSetCurrentTransactionBatchStatusFuncName).ArgInt64(int64(batch.ID)) for _, stat := range batch.Statuses { builder.ArgBytes([]byte{stat}) @@ -402,7 +412,7 @@ func (dataGetter *mxClientDataGetter) GetActionIDForSetStatusOnPendingTransfer(c // QuorumReached returns true if the provided action ID reached the set quorum func (dataGetter *mxClientDataGetter) QuorumReached(ctx context.Context, actionID uint64) (bool, error) { - builder := dataGetter.createDefaultVmQueryBuilder() + builder := dataGetter.createMultisigDefaultVmQueryBuilder() builder.Function(quorumReachedFuncName).ArgInt64(int64(actionID)) return dataGetter.executeQueryBoolFromBuilder(ctx, builder) @@ -410,21 +420,21 @@ func (dataGetter *mxClientDataGetter) QuorumReached(ctx context.Context, actionI // GetLastExecutedEthBatchID returns the last executed Ethereum batch ID func (dataGetter *mxClientDataGetter) GetLastExecutedEthBatchID(ctx context.Context) (uint64, error) { - builder := dataGetter.createDefaultVmQueryBuilder().Function(getLastExecutedEthBatchIdFuncName) + builder := dataGetter.createMultisigDefaultVmQueryBuilder().Function(getLastExecutedEthBatchIdFuncName) return dataGetter.executeQueryUint64FromBuilder(ctx, builder) } // GetLastExecutedEthTxID returns the last executed Ethereum deposit ID func (dataGetter *mxClientDataGetter) GetLastExecutedEthTxID(ctx context.Context) (uint64, error) { - builder := dataGetter.createDefaultVmQueryBuilder().Function(getLastExecutedEthTxId) + builder := dataGetter.createMultisigDefaultVmQueryBuilder().Function(getLastExecutedEthTxId) return dataGetter.executeQueryUint64FromBuilder(ctx, builder) } // WasSigned returns true if the action was already signed by the current relayer func (dataGetter *mxClientDataGetter) WasSigned(ctx context.Context, actionID uint64) (bool, error) { - builder := dataGetter.createDefaultVmQueryBuilder() + builder := dataGetter.createMultisigDefaultVmQueryBuilder() builder.Function(signedFuncName).ArgAddress(dataGetter.relayerAddress).ArgInt64(int64(actionID)) return dataGetter.executeQueryBoolFromBuilder(ctx, builder) @@ -432,7 +442,7 @@ func (dataGetter *mxClientDataGetter) WasSigned(ctx context.Context, actionID ui // GetAllStakedRelayers returns all staked relayers defined in MultiversX SC func (dataGetter *mxClientDataGetter) GetAllStakedRelayers(ctx context.Context) ([][]byte, error) { - builder := dataGetter.createDefaultVmQueryBuilder() + builder := dataGetter.createMultisigDefaultVmQueryBuilder() builder.Function(getAllStakedRelayersFuncName) return dataGetter.executeQueryFromBuilder(ctx, builder) @@ -440,21 +450,21 @@ func (dataGetter *mxClientDataGetter) GetAllStakedRelayers(ctx context.Context) // IsPaused returns true if the multisig contract is paused func (dataGetter *mxClientDataGetter) IsPaused(ctx context.Context) (bool, error) { - builder := dataGetter.createDefaultVmQueryBuilder() + builder := dataGetter.createMultisigDefaultVmQueryBuilder() builder.Function(isPausedFuncName) return dataGetter.executeQueryBoolFromBuilder(ctx, builder) } func (dataGetter *mxClientDataGetter) isMintBurnAllowed(ctx context.Context, token []byte) (bool, error) { - builder := dataGetter.createDefaultVmQueryBuilder() + builder := dataGetter.createSafeDefaultVmQueryBuilder() builder.Function(isMintBurnAllowedFuncName).ArgBytes(token) return dataGetter.executeQueryBoolFromBuilder(ctx, builder) } func (dataGetter *mxClientDataGetter) getAccumulatedBurnedTokens(ctx context.Context, token []byte) (*big.Int, error) { - builder := dataGetter.createDefaultVmQueryBuilder() + builder := dataGetter.createSafeDefaultVmQueryBuilder() builder.Function(getAccumulatedBurnedTokensFuncName).ArgBytes(token) return dataGetter.executeQueryBigIntFromBuilder(ctx, builder) diff --git a/clients/multiversx/mxClientDataGetter_test.go b/clients/multiversx/mxClientDataGetter_test.go index b9ba823f..12bf106f 100644 --- a/clients/multiversx/mxClientDataGetter_test.go +++ b/clients/multiversx/mxClientDataGetter_test.go @@ -36,6 +36,7 @@ func createMockArgsMXClientDataGetter() ArgsMXClientDataGetter { } args.MultisigContractAddress, _ = data.NewAddressFromBech32String("erd1qqqqqqqqqqqqqpgqzyuaqg3dl7rqlkudrsnm5ek0j3a97qevd8sszj0glf") + args.SafeContractAddress, _ = data.NewAddressFromBech32String("erd1qqqqqqqqqqqqqpgqtvnswnzxxz8susupesys0hvg7q2z5nawrcjq06qdus") args.RelayerAddress, _ = data.NewAddressFromBech32String("erd1r69gk66fmedhhcg24g2c5kn2f2a5k4kvpr6jfw67dn2lyydd8cfswy6ede") return args @@ -125,6 +126,17 @@ func TestNewMXClientDataGetter(t *testing.T) { assert.True(t, strings.Contains(err.Error(), "MultisigContractAddress")) assert.True(t, check.IfNil(dg)) }) + t.Run("nil safe contact address", func(t *testing.T) { + t.Parallel() + + args := createMockArgsMXClientDataGetter() + args.SafeContractAddress = nil + + dg, err := NewMXClientDataGetter(args) + assert.True(t, errors.Is(err, errNilAddressHandler)) + assert.True(t, strings.Contains(err.Error(), "SafeContractAddress")) + assert.True(t, check.IfNil(dg)) + }) t.Run("nil relayer address", func(t *testing.T) { t.Parallel() @@ -1378,3 +1390,68 @@ func TestMultiversXClientDataGetter_IsPaused(t *testing.T) { assert.True(t, result) assert.True(t, proxyCalled) } + +func TestMultiversXClientDataGetter_isMintBurnAllowed(t *testing.T) { + t.Parallel() + + args := createMockArgsMXClientDataGetter() + proxyCalled := false + args.Proxy = &interactors.ProxyStub{ + ExecuteVMQueryCalled: func(ctx context.Context, vmRequest *data.VmValueRequest) (*data.VmValuesResponseData, error) { + proxyCalled = true + assert.Equal(t, getBech32Address(args.SafeContractAddress), vmRequest.Address) + assert.Equal(t, getBech32Address(args.RelayerAddress), vmRequest.CallerAddr) + assert.Equal(t, "", vmRequest.CallValue) + assert.Equal(t, isMintBurnAllowedFuncName, vmRequest.FuncName) + assert.Equal(t, []string{"746f6b656e"}, vmRequest.Args) + + strResponse := "AQ==" + response, _ := base64.StdEncoding.DecodeString(strResponse) + return &data.VmValuesResponseData{ + Data: &vm.VMOutputApi{ + ReturnCode: okCodeAfterExecution, + ReturnData: [][]byte{response}, + }, + }, nil + }, + } + + dg, _ := NewMXClientDataGetter(args) + + result, err := dg.isMintBurnAllowed(context.Background(), []byte("token")) + assert.Nil(t, err) + assert.True(t, result) + assert.True(t, proxyCalled) +} + +func TestMultiversXClientDataGetter_getAccumulatedBurnedTokens(t *testing.T) { + t.Parallel() + + args := createMockArgsMXClientDataGetter() + proxyCalled := false + expectedAccumulatedBurnedTokens := big.NewInt(100) + args.Proxy = &interactors.ProxyStub{ + ExecuteVMQueryCalled: func(ctx context.Context, vmRequest *data.VmValueRequest) (*data.VmValuesResponseData, error) { + proxyCalled = true + assert.Equal(t, getBech32Address(args.SafeContractAddress), vmRequest.Address) + assert.Equal(t, getBech32Address(args.RelayerAddress), vmRequest.CallerAddr) + assert.Equal(t, "", vmRequest.CallValue) + assert.Equal(t, getAccumulatedBurnedTokensFuncName, vmRequest.FuncName) + assert.Equal(t, []string{"746f6b656e"}, vmRequest.Args) + + return &data.VmValuesResponseData{ + Data: &vm.VMOutputApi{ + ReturnCode: okCodeAfterExecution, + ReturnData: [][]byte{expectedAccumulatedBurnedTokens.Bytes()}, + }, + }, nil + }, + } + + dg, _ := NewMXClientDataGetter(args) + + result, err := dg.getAccumulatedBurnedTokens(context.Background(), []byte("token")) + assert.Nil(t, err) + assert.Equal(t, result, expectedAccumulatedBurnedTokens) + assert.True(t, proxyCalled) +} diff --git a/cmd/bridge/config/config.toml b/cmd/bridge/config/config.toml index 3838f848..43982f5b 100644 --- a/cmd/bridge/config/config.toml +++ b/cmd/bridge/config/config.toml @@ -25,6 +25,7 @@ [MultiversX] NetworkAddress = "https://devnet-gateway.multiversx.com" # the network address MultisigContractAddress = "erd1qqqqqqqqqqqqqpgqzyuaqg3dl7rqlkudrsnm5ek0j3a97qevd8sszj0glf" # the multiversx address for the bridge contract + SafeContractAddress = "erd1qqqqqqqqqqqqqpgqtvnswnzxxz8susupesys0hvg7q2z5nawrcjq06qdus" # the multiversx address for the safe contract PrivateKeyFile = "keys/multiversx.pem" # the path to the pem file containing the relayer multiversx wallet IntervalToResendTxsInSeconds = 60 # the time in seconds between nonce reads MaxRetriesOnQuorumReached = 3 diff --git a/config/config.go b/config/config.go index 6bb03463..c41d60db 100644 --- a/config/config.go +++ b/config/config.go @@ -150,6 +150,7 @@ type RoleProviderConfig struct { type MultiversXConfig struct { NetworkAddress string MultisigContractAddress string + SafeContractAddress string PrivateKeyFile string IntervalToResendTxsInSeconds uint64 GasMap MultiversXGasMapConfig diff --git a/factory/ethMultiversXBridgeComponents.go b/factory/ethMultiversXBridgeComponents.go index 09a67111..e3d71698 100644 --- a/factory/ethMultiversXBridgeComponents.go +++ b/factory/ethMultiversXBridgeComponents.go @@ -81,6 +81,7 @@ type ethMultiversXBridgeComponents struct { ethClient ethmultiversx.EthereumClient evmCompatibleChain chain.Chain multiversXMultisigContractAddress sdkCore.AddressHandler + multiversXSafeContractAddress sdkCore.AddressHandler multiversXRelayerPrivateKey crypto.PrivateKey multiversXRelayerAddress sdkCore.AddressHandler ethereumRelayerAddress common.Address @@ -259,6 +260,11 @@ func (components *ethMultiversXBridgeComponents) createMultiversXKeysAndAddresse return fmt.Errorf("%w for chainConfigs.MultisigContractAddress", err) } + components.multiversXSafeContractAddress, err = data.NewAddressFromBech32String(chainConfigs.SafeContractAddress) + if err != nil { + return fmt.Errorf("%w for chainConfigs.MultisigContractAddress", err) + } + return nil } @@ -266,6 +272,7 @@ func (components *ethMultiversXBridgeComponents) createDataGetter() error { multiversXDataGetterLogId := components.evmCompatibleChain.MultiversXDataGetterLogId() argsMXClientDataGetter := multiversx.ArgsMXClientDataGetter{ MultisigContractAddress: components.multiversXMultisigContractAddress, + SafeContractAddress: components.multiversXSafeContractAddress, RelayerAddress: components.multiversXRelayerAddress, Proxy: components.proxy, Log: core.NewLoggerWithIdentifier(logger.GetOrCreate(multiversXDataGetterLogId), multiversXDataGetterLogId), From 95626cb493f54610193e276b5a86f41434d62662 Mon Sep 17 00:00:00 2001 From: dragosrebegea Date: Tue, 23 Jan 2024 20:07:39 +0200 Subject: [PATCH 2/3] MX-15083: fix unit tests --- clients/multiversx/client.go | 15 ++++++++++++++- clients/multiversx/client_test.go | 13 +++++++++++++ config/tomlConfigs_test.go | 1 + factory/ethMultiversXBridgeComponents.go | 3 ++- factory/ethMultiversXBridgeComponents_test.go | 1 + integrationTests/relayers/ethToMultiversX_test.go | 1 + 6 files changed, 32 insertions(+), 2 deletions(-) diff --git a/clients/multiversx/client.go b/clients/multiversx/client.go index cb666ef5..38d02b37 100644 --- a/clients/multiversx/client.go +++ b/clients/multiversx/client.go @@ -40,6 +40,7 @@ type ClientArgs struct { Log logger.Logger RelayerPrivateKey crypto.PrivateKey MultisigContractAddress core.AddressHandler + SafeContractAddress core.AddressHandler IntervalToResendTxsInSeconds uint64 TokensMapper TokensMapper RoleProvider roleProvider @@ -55,6 +56,7 @@ type client struct { relayerPublicKey crypto.PublicKey relayerAddress core.AddressHandler multisigContractAddress core.AddressHandler + safeContractAddress core.AddressHandler log logger.Logger gasMapConfig config.MultiversXGasMapConfig addressPublicKeyConverter bridgeCore.AddressConverter @@ -97,6 +99,7 @@ func NewClient(args ClientArgs) (*client, error) { argsMXClientDataGetter := ArgsMXClientDataGetter{ MultisigContractAddress: args.MultisigContractAddress, + SafeContractAddress: args.SafeContractAddress, RelayerAddress: relayerAddress, Proxy: args.Proxy, Log: bridgeCore.NewLoggerWithIdentifier(logger.GetOrCreate(multiversXDataGetterLogId), multiversXDataGetterLogId), @@ -116,6 +119,11 @@ func NewClient(args ClientArgs) (*client, error) { return nil, fmt.Errorf("%w for %x", err, args.MultisigContractAddress.AddressBytes()) } + bech23SafeAddress, err := args.SafeContractAddress.AddressAsBech32String() + if err != nil { + return nil, fmt.Errorf("%w for %x", err, args.SafeContractAddress.AddressBytes()) + } + c := &client{ txHandler: &transactionHandler{ proxy: args.Proxy, @@ -130,6 +138,7 @@ func NewClient(args ClientArgs) (*client, error) { relayerPublicKey: publicKey, relayerAddress: relayerAddress, multisigContractAddress: args.MultisigContractAddress, + safeContractAddress: args.SafeContractAddress, log: args.Log, gasMapConfig: args.GasMapConfig, addressPublicKeyConverter: addressConverter, @@ -141,7 +150,8 @@ func NewClient(args ClientArgs) (*client, error) { bech32RelayerAddress, _ := relayerAddress.AddressAsBech32String() c.log.Info("NewMultiversXClient", "relayer address", bech32RelayerAddress, - "safe contract address", bech23MultisigAddress) + "multisig contract address", bech23MultisigAddress, + "safe contract address", bech23SafeAddress) return c, nil } @@ -156,6 +166,9 @@ func checkArgs(args ClientArgs) error { if check.IfNil(args.MultisigContractAddress) { return fmt.Errorf("%w for the MultisigContractAddress argument", errNilAddressHandler) } + if check.IfNil(args.SafeContractAddress) { + return fmt.Errorf("%w for the SafeContractAddress argument", errNilAddressHandler) + } if check.IfNil(args.Log) { return clients.ErrNilLogger } diff --git a/clients/multiversx/client_test.go b/clients/multiversx/client_test.go index 3ea04ccb..f1cf16b8 100644 --- a/clients/multiversx/client_test.go +++ b/clients/multiversx/client_test.go @@ -35,6 +35,7 @@ var pausedBytes = []byte{1} func createMockClientArgs() ClientArgs { privateKey, _ := testKeyGen.PrivateKeyFromByteArray(bytes.Repeat([]byte{1}, 32)) multisigContractAddress, _ := data.NewAddressFromBech32String("erd1qqqqqqqqqqqqqpgqzyuaqg3dl7rqlkudrsnm5ek0j3a97qevd8sszj0glf") + safeContractAddress, _ := data.NewAddressFromBech32String("erd1qqqqqqqqqqqqqpgqzyuaqg3dl7rqlkudrsnm5ek0j3a97qevd8sszj0glf") return ClientArgs{ GasMapConfig: config.MultiversXGasMapConfig{ @@ -52,6 +53,7 @@ func createMockClientArgs() ClientArgs { Log: logger.GetOrCreate("test"), RelayerPrivateKey: privateKey, MultisigContractAddress: multisigContractAddress, + SafeContractAddress: safeContractAddress, IntervalToResendTxsInSeconds: 1, TokensMapper: &bridgeTests.TokensMapperStub{ ConvertTokenCalled: func(ctx context.Context, sourceBytes []byte) ([]byte, error) { @@ -125,6 +127,17 @@ func TestNewClient(t *testing.T) { require.True(t, check.IfNil(c)) require.True(t, errors.Is(err, errNilAddressHandler)) }) + t.Run("nil safe contract address should error", func(t *testing.T) { + t.Parallel() + + args := createMockClientArgs() + args.SafeContractAddress = nil + + c, err := NewClient(args) + + require.True(t, check.IfNil(c)) + require.True(t, errors.Is(err, errNilAddressHandler)) + }) t.Run("nil logger should error", func(t *testing.T) { t.Parallel() diff --git a/config/tomlConfigs_test.go b/config/tomlConfigs_test.go index 574a0e9b..35b4c71e 100644 --- a/config/tomlConfigs_test.go +++ b/config/tomlConfigs_test.go @@ -40,6 +40,7 @@ func TestConfigs(t *testing.T) { MultiversX: MultiversXConfig{ NetworkAddress: "https://devnet-gateway.multiversx.com", MultisigContractAddress: "erd1qqqqqqqqqqqqqpgqzyuaqg3dl7rqlkudrsnm5ek0j3a97qevd8sszj0glf", + SafeContractAddress: "erd1qqqqqqqqqqqqqpgqzyuaqg3dl7rqlkudrsnm5ek0j3a97qevd8sszj0glf", PrivateKeyFile: "keys/multiversx.pem", IntervalToResendTxsInSeconds: 60, GasMap: MultiversXGasMapConfig{ diff --git a/factory/ethMultiversXBridgeComponents.go b/factory/ethMultiversXBridgeComponents.go index e3d71698..3f5f3fac 100644 --- a/factory/ethMultiversXBridgeComponents.go +++ b/factory/ethMultiversXBridgeComponents.go @@ -262,7 +262,7 @@ func (components *ethMultiversXBridgeComponents) createMultiversXKeysAndAddresse components.multiversXSafeContractAddress, err = data.NewAddressFromBech32String(chainConfigs.SafeContractAddress) if err != nil { - return fmt.Errorf("%w for chainConfigs.MultisigContractAddress", err) + return fmt.Errorf("%w for chainConfigs.SafeContractAddress", err) } return nil @@ -298,6 +298,7 @@ func (components *ethMultiversXBridgeComponents) createMultiversXClient(args Arg Log: core.NewLoggerWithIdentifier(logger.GetOrCreate(multiversXClientLogId), multiversXClientLogId), RelayerPrivateKey: components.multiversXRelayerPrivateKey, MultisigContractAddress: components.multiversXMultisigContractAddress, + SafeContractAddress: components.multiversXSafeContractAddress, IntervalToResendTxsInSeconds: chainConfigs.IntervalToResendTxsInSeconds, TokensMapper: tokensMapper, RoleProvider: components.multiversXRoleProvider, diff --git a/factory/ethMultiversXBridgeComponents_test.go b/factory/ethMultiversXBridgeComponents_test.go index 39c92192..007467ef 100644 --- a/factory/ethMultiversXBridgeComponents_test.go +++ b/factory/ethMultiversXBridgeComponents_test.go @@ -59,6 +59,7 @@ func createMockEthMultiversXBridgeArgs() ArgsEthereumToMultiversXBridge { IntervalToResendTxsInSeconds: 60, NetworkAddress: "http://127.0.0.1:8079", MultisigContractAddress: "erd1qqqqqqqqqqqqqpgqgftcwj09u0nhmskrw7xxqcqh8qmzwyexd8ss7ftcxx", + SafeContractAddress: "erd1qqqqqqqqqqqqqpgqgftcwj09u0nhmskrw7xxqcqh8qmzwyexd8ss7ftcxx", GasMap: testsCommon.CreateTestMultiversXGasMap(), MaxRetriesOnQuorumReached: 1, MaxRetriesOnWasTransferProposed: 1, diff --git a/integrationTests/relayers/ethToMultiversX_test.go b/integrationTests/relayers/ethToMultiversX_test.go index 1ceefa2c..99279332 100644 --- a/integrationTests/relayers/ethToMultiversX_test.go +++ b/integrationTests/relayers/ethToMultiversX_test.go @@ -430,6 +430,7 @@ func createBridgeComponentsConfig(index int) config.Config { MultiversX: config.MultiversXConfig{ NetworkAddress: "mock", MultisigContractAddress: "erd1qqqqqqqqqqqqqpgqzyuaqg3dl7rqlkudrsnm5ek0j3a97qevd8sszj0glf", + SafeContractAddress: "erd1qqqqqqqqqqqqqpgqtvnswnzxxz8susupesys0hvg7q2z5nawrcjq06qdus", PrivateKeyFile: fmt.Sprintf("testdata/multiversx%d.pem", index), IntervalToResendTxsInSeconds: 10, GasMap: testsCommon.CreateTestMultiversXGasMap(), From ad67f1280ddfeec2259d0f5c3d80f6f80fe4989b Mon Sep 17 00:00:00 2001 From: dragosrebegea Date: Tue, 23 Jan 2024 20:12:22 +0200 Subject: [PATCH 3/3] MX-15083: fix unit tests --- clients/multiversx/client_test.go | 2 +- config/tomlConfigs_test.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/clients/multiversx/client_test.go b/clients/multiversx/client_test.go index f1cf16b8..c086086d 100644 --- a/clients/multiversx/client_test.go +++ b/clients/multiversx/client_test.go @@ -35,7 +35,7 @@ var pausedBytes = []byte{1} func createMockClientArgs() ClientArgs { privateKey, _ := testKeyGen.PrivateKeyFromByteArray(bytes.Repeat([]byte{1}, 32)) multisigContractAddress, _ := data.NewAddressFromBech32String("erd1qqqqqqqqqqqqqpgqzyuaqg3dl7rqlkudrsnm5ek0j3a97qevd8sszj0glf") - safeContractAddress, _ := data.NewAddressFromBech32String("erd1qqqqqqqqqqqqqpgqzyuaqg3dl7rqlkudrsnm5ek0j3a97qevd8sszj0glf") + safeContractAddress, _ := data.NewAddressFromBech32String("erd1qqqqqqqqqqqqqpgqtvnswnzxxz8susupesys0hvg7q2z5nawrcjq06qdus") return ClientArgs{ GasMapConfig: config.MultiversXGasMapConfig{ diff --git a/config/tomlConfigs_test.go b/config/tomlConfigs_test.go index 35b4c71e..7b6d378c 100644 --- a/config/tomlConfigs_test.go +++ b/config/tomlConfigs_test.go @@ -40,7 +40,7 @@ func TestConfigs(t *testing.T) { MultiversX: MultiversXConfig{ NetworkAddress: "https://devnet-gateway.multiversx.com", MultisigContractAddress: "erd1qqqqqqqqqqqqqpgqzyuaqg3dl7rqlkudrsnm5ek0j3a97qevd8sszj0glf", - SafeContractAddress: "erd1qqqqqqqqqqqqqpgqzyuaqg3dl7rqlkudrsnm5ek0j3a97qevd8sszj0glf", + SafeContractAddress: "erd1qqqqqqqqqqqqqpgqtvnswnzxxz8susupesys0hvg7q2z5nawrcjq06qdus", PrivateKeyFile: "keys/multiversx.pem", IntervalToResendTxsInSeconds: 60, GasMap: MultiversXGasMapConfig{ @@ -243,6 +243,7 @@ func TestConfigs(t *testing.T) { [MultiversX] NetworkAddress = "https://devnet-gateway.multiversx.com" # the network address MultisigContractAddress = "erd1qqqqqqqqqqqqqpgqzyuaqg3dl7rqlkudrsnm5ek0j3a97qevd8sszj0glf" # the multiversx address for the bridge contract + SafeContractAddress = "erd1qqqqqqqqqqqqqpgqtvnswnzxxz8susupesys0hvg7q2z5nawrcjq06qdus" # the multiversx address for the safe contract PrivateKeyFile = "keys/multiversx.pem" # the path to the pem file containing the relayer multiversx wallet IntervalToResendTxsInSeconds = 60 # the time in seconds between nonce reads MaxRetriesOnQuorumReached = 3