diff --git a/cmd/bee/cmd/cmd.go b/cmd/bee/cmd/cmd.go index 344cb05d894..ffe6bc06d01 100644 --- a/cmd/bee/cmd/cmd.go +++ b/cmd/bee/cmd/cmd.go @@ -22,70 +22,69 @@ import ( ) const ( - optionNameDataDir = "data-dir" - optionNameCacheCapacity = "cache-capacity" - optionNameDBOpenFilesLimit = "db-open-files-limit" - optionNameDBBlockCacheCapacity = "db-block-cache-capacity" - optionNameDBWriteBufferSize = "db-write-buffer-size" - optionNameDBDisableSeeksCompaction = "db-disable-seeks-compaction" - optionNamePassword = "password" - optionNamePasswordFile = "password-file" - optionNameAPIAddr = "api-addr" - optionNameP2PAddr = "p2p-addr" - optionNameNATAddr = "nat-addr" - optionNameP2PWSEnable = "p2p-ws-enable" - optionNameDebugAPIEnable = "debug-api-enable" - optionNameDebugAPIAddr = "debug-api-addr" - optionNameBootnodes = "bootnode" - optionNameNetworkID = "network-id" - optionWelcomeMessage = "welcome-message" - optionCORSAllowedOrigins = "cors-allowed-origins" - optionNameTracingEnabled = "tracing-enable" - optionNameTracingEndpoint = "tracing-endpoint" - optionNameTracingHost = "tracing-host" - optionNameTracingPort = "tracing-port" - optionNameTracingServiceName = "tracing-service-name" - optionNameVerbosity = "verbosity" - optionNamePaymentThreshold = "payment-threshold" - optionNamePaymentTolerance = "payment-tolerance-percent" - optionNamePaymentEarly = "payment-early-percent" - optionNameResolverEndpoints = "resolver-options" - optionNameBootnodeMode = "bootnode-mode" - optionNameClefSignerEnable = "clef-signer-enable" - optionNameClefSignerEndpoint = "clef-signer-endpoint" - optionNameClefSignerEthereumAddress = "clef-signer-ethereum-address" - optionNameSwapEndpoint = "swap-endpoint" // deprecated: use rpc endpoint instead - optionNameBlockchainRpcEndpoint = "blockchain-rpc-endpoint" - optionNameSwapFactoryAddress = "swap-factory-address" - optionNameSwapLegacyFactoryAddresses = "swap-legacy-factory-addresses" - optionNameSwapInitialDeposit = "swap-initial-deposit" - optionNameSwapEnable = "swap-enable" - optionNameChequebookEnable = "chequebook-enable" - optionNameSwapDeploymentGasPrice = "swap-deployment-gas-price" - optionNameFullNode = "full-node" - optionNamePostageContractAddress = "postage-stamp-address" - optionNamePostageContractStartBlock = "postage-stamp-start-block" - optionNamePriceOracleAddress = "price-oracle-address" - optionNameRedistributionAddress = "redistribution-address" - optionNameStakingAddress = "staking-address" - optionNameBlockTime = "block-time" - optionWarmUpTime = "warmup-time" - optionNameMainNet = "mainnet" - optionNameRetrievalCaching = "cache-retrieval" - optionNameDevReserveCapacity = "dev-reserve-capacity" - optionNameResync = "resync" - optionNamePProfBlock = "pprof-profile" - optionNamePProfMutex = "pprof-mutex" - optionNameStaticNodes = "static-nodes" - optionNameAllowPrivateCIDRs = "allow-private-cidrs" - optionNameSleepAfter = "sleep-after" - optionNameRestrictedAPI = "restricted" - optionNameTokenEncryptionKey = "token-encryption-key" - optionNameAdminPasswordHash = "admin-password" - optionNameUsePostageSnapshot = "use-postage-snapshot" - optionNameStorageIncentivesEnable = "storage-incentives-enable" - optionNameStateStoreCacheCapacity = "statestore-cache-capacity" - optionNameTargetNeighborhood = "target-neighborhood" + optionNameDataDir = "data-dir" + optionNameCacheCapacity = "cache-capacity" + optionNameDBOpenFilesLimit = "db-open-files-limit" + optionNameDBBlockCacheCapacity = "db-block-cache-capacity" + optionNameDBWriteBufferSize = "db-write-buffer-size" + optionNameDBDisableSeeksCompaction = "db-disable-seeks-compaction" + optionNamePassword = "password" + optionNamePasswordFile = "password-file" + optionNameAPIAddr = "api-addr" + optionNameP2PAddr = "p2p-addr" + optionNameNATAddr = "nat-addr" + optionNameP2PWSEnable = "p2p-ws-enable" + optionNameDebugAPIEnable = "debug-api-enable" + optionNameDebugAPIAddr = "debug-api-addr" + optionNameBootnodes = "bootnode" + optionNameNetworkID = "network-id" + optionWelcomeMessage = "welcome-message" + optionCORSAllowedOrigins = "cors-allowed-origins" + optionNameTracingEnabled = "tracing-enable" + optionNameTracingEndpoint = "tracing-endpoint" + optionNameTracingHost = "tracing-host" + optionNameTracingPort = "tracing-port" + optionNameTracingServiceName = "tracing-service-name" + optionNameVerbosity = "verbosity" + optionNamePaymentThreshold = "payment-threshold" + optionNamePaymentTolerance = "payment-tolerance-percent" + optionNamePaymentEarly = "payment-early-percent" + optionNameResolverEndpoints = "resolver-options" + optionNameBootnodeMode = "bootnode-mode" + optionNameClefSignerEnable = "clef-signer-enable" + optionNameClefSignerEndpoint = "clef-signer-endpoint" + optionNameClefSignerEthereumAddress = "clef-signer-ethereum-address" + optionNameSwapEndpoint = "swap-endpoint" // deprecated: use rpc endpoint instead + optionNameBlockchainRpcEndpoint = "blockchain-rpc-endpoint" + optionNameSwapFactoryAddress = "swap-factory-address" + optionNameSwapInitialDeposit = "swap-initial-deposit" + optionNameSwapEnable = "swap-enable" + optionNameChequebookEnable = "chequebook-enable" + optionNameSwapDeploymentGasPrice = "swap-deployment-gas-price" + optionNameFullNode = "full-node" + optionNamePostageContractAddress = "postage-stamp-address" + optionNamePostageContractStartBlock = "postage-stamp-start-block" + optionNamePriceOracleAddress = "price-oracle-address" + optionNameRedistributionAddress = "redistribution-address" + optionNameStakingAddress = "staking-address" + optionNameBlockTime = "block-time" + optionWarmUpTime = "warmup-time" + optionNameMainNet = "mainnet" + optionNameRetrievalCaching = "cache-retrieval" + optionNameDevReserveCapacity = "dev-reserve-capacity" + optionNameResync = "resync" + optionNamePProfBlock = "pprof-profile" + optionNamePProfMutex = "pprof-mutex" + optionNameStaticNodes = "static-nodes" + optionNameAllowPrivateCIDRs = "allow-private-cidrs" + optionNameSleepAfter = "sleep-after" + optionNameRestrictedAPI = "restricted" + optionNameTokenEncryptionKey = "token-encryption-key" + optionNameAdminPasswordHash = "admin-password" + optionNameUsePostageSnapshot = "use-postage-snapshot" + optionNameStorageIncentivesEnable = "storage-incentives-enable" + optionNameStateStoreCacheCapacity = "statestore-cache-capacity" + optionNameTargetNeighborhood = "target-neighborhood" ) // nolint:gochecknoinits @@ -277,7 +276,6 @@ func (c *command) setAllFlags(cmd *cobra.Command) { cmd.Flags().String(optionNameSwapEndpoint, "", "swap blockchain endpoint") // deprecated: use rpc endpoint instead cmd.Flags().String(optionNameBlockchainRpcEndpoint, "", "rpc blockchain endpoint") cmd.Flags().String(optionNameSwapFactoryAddress, "", "swap factory addresses") - cmd.Flags().StringSlice(optionNameSwapLegacyFactoryAddresses, nil, "legacy swap factory addresses") cmd.Flags().String(optionNameSwapInitialDeposit, "0", "initial deposit if deploying a new chequebook") cmd.Flags().Bool(optionNameSwapEnable, false, "enable swap") cmd.Flags().Bool(optionNameChequebookEnable, true, "enable chequebook") diff --git a/cmd/bee/cmd/deploy.go b/cmd/bee/cmd/deploy.go index 24887e90b53..7b3e8e57734 100644 --- a/cmd/bee/cmd/deploy.go +++ b/cmd/bee/cmd/deploy.go @@ -71,14 +71,7 @@ func (c *command) initDeployCmd() error { defer swapBackend.Close() defer transactionMonitor.Close() - chequebookFactory, err := node.InitChequebookFactory( - logger, - swapBackend, - chainID, - transactionService, - factoryAddress, - nil, - ) + chequebookFactory, err := node.InitChequebookFactory(logger, swapBackend, chainID, transactionService, factoryAddress) if err != nil { return err } diff --git a/cmd/bee/cmd/start.go b/cmd/bee/cmd/start.go index e76719669af..ee287a2104a 100644 --- a/cmd/bee/cmd/start.go +++ b/cmd/bee/cmd/start.go @@ -313,7 +313,6 @@ func buildBeeNode(ctx context.Context, c *command, cmd *cobra.Command, logger lo BootnodeMode: bootNode, BlockchainRpcEndpoint: blockchainRpcEndpoint, SwapFactoryAddress: c.config.GetString(optionNameSwapFactoryAddress), - SwapLegacyFactoryAddresses: c.config.GetStringSlice(optionNameSwapLegacyFactoryAddresses), SwapInitialDeposit: c.config.GetString(optionNameSwapInitialDeposit), SwapEnable: c.config.GetBool(optionNameSwapEnable), ChequebookEnable: c.config.GetBool(optionNameChequebookEnable), diff --git a/pkg/config/chain.go b/pkg/config/chain.go index d87ad99b17c..e551b3a1c47 100644 --- a/pkg/config/chain.go +++ b/pkg/config/chain.go @@ -27,7 +27,6 @@ type ChainConfig struct { RedistributionAddress common.Address SwapPriceOracleAddress common.Address CurrentFactoryAddress common.Address - LegacyFactoryAddresses []common.Address // ABIs. StakingABI string diff --git a/pkg/node/chain.go b/pkg/node/chain.go index 40a616d92bf..c4cab943207 100644 --- a/pkg/node/chain.go +++ b/pkg/node/chain.go @@ -100,20 +100,11 @@ func InitChain( // InitChequebookFactory will initialize the chequebook factory with the given // chain backend. -func InitChequebookFactory( - logger log.Logger, - backend transaction.Backend, - chainID int64, - transactionService transaction.Service, - factoryAddress string, - legacyFactoryAddresses []string, -) (chequebook.Factory, error) { +func InitChequebookFactory(logger log.Logger, backend transaction.Backend, chainID int64, transactionService transaction.Service, factoryAddress string) (chequebook.Factory, error) { var currentFactory common.Address - var legacyFactories []common.Address - chainCfg, found := config.GetByChainID(chainID) - foundFactory, foundLegacyFactories := chainCfg.CurrentFactoryAddress, chainCfg.LegacyFactoryAddresses + foundFactory := chainCfg.CurrentFactoryAddress if factoryAddress == "" { if !found { return nil, fmt.Errorf("no known factory address for this network (chain id: %d)", chainID) @@ -127,25 +118,7 @@ func InitChequebookFactory( logger.Info("using custom factory address", "factory_address", currentFactory) } - if len(legacyFactoryAddresses) == 0 { - if found { - legacyFactories = foundLegacyFactories - } - } else { - for _, legacyAddress := range legacyFactoryAddresses { - if !common.IsHexAddress(legacyAddress) { - return nil, errors.New("malformed factory address") - } - legacyFactories = append(legacyFactories, common.HexToAddress(legacyAddress)) - } - } - - return chequebook.NewFactory( - backend, - transactionService, - currentFactory, - legacyFactories, - ), nil + return chequebook.NewFactory(backend, transactionService, currentFactory), nil } // InitChequebookService will initialize the chequebook service with the given diff --git a/pkg/node/node.go b/pkg/node/node.go index 36cd9361f73..6c8aef8e4bf 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -146,7 +146,6 @@ type Options struct { BootnodeMode bool BlockchainRpcEndpoint string SwapFactoryAddress string - SwapLegacyFactoryAddresses []string SwapInitialDeposit string SwapEnable bool ChequebookEnable bool @@ -504,22 +503,11 @@ func NewBee( } if o.SwapEnable { - chequebookFactory, err = InitChequebookFactory( - logger, - chainBackend, - chainID, - transactionService, - o.SwapFactoryAddress, - o.SwapLegacyFactoryAddresses, - ) + chequebookFactory, err = InitChequebookFactory(logger, chainBackend, chainID, transactionService, o.SwapFactoryAddress) if err != nil { return nil, err } - if err = chequebookFactory.VerifyBytecode(ctx); err != nil { - return nil, fmt.Errorf("factory fail: %w", err) - } - erc20Address, err := chequebookFactory.ERC20Address(ctx) if err != nil { return nil, fmt.Errorf("factory fail: %w", err) diff --git a/pkg/settlement/swap/chequebook/common_test.go b/pkg/settlement/swap/chequebook/common_test.go index b2057272f11..ef3b6988c25 100644 --- a/pkg/settlement/swap/chequebook/common_test.go +++ b/pkg/settlement/swap/chequebook/common_test.go @@ -24,7 +24,6 @@ type factoryMock struct { erc20Address func(ctx context.Context) (common.Address, error) deploy func(ctx context.Context, issuer common.Address, defaultHardDepositTimeoutDuration *big.Int, nonce common.Hash) (common.Hash, error) waitDeployed func(ctx context.Context, txHash common.Hash) (common.Address, error) - verifyBytecode func(ctx context.Context) error verifyChequebook func(ctx context.Context, chequebook common.Address) error } @@ -41,11 +40,6 @@ func (m *factoryMock) WaitDeployed(ctx context.Context, txHash common.Hash) (com return m.waitDeployed(ctx, txHash) } -// VerifyBytecode checks that the factory is valid. -func (m *factoryMock) VerifyBytecode(ctx context.Context) error { - return m.verifyBytecode(ctx) -} - // VerifyChequebook checks that the supplied chequebook has been deployed by this factory. func (m *factoryMock) VerifyChequebook(ctx context.Context, chequebook common.Address) error { return m.verifyChequebook(ctx, chequebook) diff --git a/pkg/settlement/swap/chequebook/factory.go b/pkg/settlement/swap/chequebook/factory.go index 262ef1f8ba7..0f8bf3aea2f 100644 --- a/pkg/settlement/swap/chequebook/factory.go +++ b/pkg/settlement/swap/chequebook/factory.go @@ -5,7 +5,6 @@ package chequebook import ( - "bytes" "errors" "fmt" "math/big" @@ -36,8 +35,6 @@ type Factory interface { Deploy(ctx context.Context, issuer common.Address, defaultHardDepositTimeoutDuration *big.Int, nonce common.Hash) (common.Hash, error) // WaitDeployed waits for the deployment transaction to confirm and returns the chequebook address WaitDeployed(ctx context.Context, txHash common.Hash) (common.Address, error) - // VerifyBytecode checks that the factory is valid. - VerifyBytecode(ctx context.Context) error // VerifyChequebook checks that the supplied chequebook has been deployed by this factory. VerifyChequebook(ctx context.Context, chequebook common.Address) error } @@ -45,29 +42,19 @@ type Factory interface { type factory struct { backend transaction.Backend transactionService transaction.Service - address common.Address // address of the factory to use for deployments - legacyAddresses []common.Address // addresses of old factories which were allowed for deployment + address common.Address // address of the factory to use for deployments } type simpleSwapDeployedEvent struct { ContractAddress common.Address } -// the bytecode of factories which can be used for deployment -var currentDeployVersion = common.FromHex(sw3abi.SimpleSwapFactoryDeployedBinv0_6_5) - -// the bytecode of factories from which we accept chequebooks -var supportedVersions = [][]byte{ - currentDeployVersion, -} - // NewFactory creates a new factory service for the provided factory contract. -func NewFactory(backend transaction.Backend, transactionService transaction.Service, address common.Address, legacyAddresses []common.Address) Factory { +func NewFactory(backend transaction.Backend, transactionService transaction.Service, address common.Address) Factory { return &factory{ backend: backend, transactionService: transactionService, address: address, - legacyAddresses: legacyAddresses, } } @@ -111,36 +98,6 @@ func (c *factory) WaitDeployed(ctx context.Context, txHash common.Hash) (common. return event.ContractAddress, nil } -// VerifyBytecode checks that the factory is valid. -func (c *factory) VerifyBytecode(ctx context.Context) (err error) { - code, err := c.backend.CodeAt(ctx, c.address, nil) - if err != nil { - return err - } - - if !bytes.Equal(code, currentDeployVersion) { - return ErrInvalidFactory - } - -LOOP: - for _, factoryAddress := range c.legacyAddresses { - code, err := c.backend.CodeAt(ctx, factoryAddress, nil) - if err != nil { - return err - } - - for _, referenceCode := range supportedVersions { - if bytes.Equal(code, referenceCode) { - continue LOOP - } - } - - return fmt.Errorf("failed to find matching bytecode for factory %x: %w", factoryAddress, ErrInvalidFactory) - } - - return nil -} - func (c *factory) verifyChequebookAgainstFactory(ctx context.Context, factory, chequebook common.Address) (bool, error) { callData, err := factoryABI.Pack("deployedContracts", chequebook) if err != nil { @@ -183,17 +140,6 @@ func (c *factory) VerifyChequebook(ctx context.Context, chequebook common.Addres if deployed { return nil } - - for _, factoryAddress := range c.legacyAddresses { - deployed, err := c.verifyChequebookAgainstFactory(ctx, factoryAddress, chequebook) - if err != nil { - return err - } - if deployed { - return nil - } - } - return ErrNotDeployedByFactory } diff --git a/pkg/settlement/swap/chequebook/factory_test.go b/pkg/settlement/swap/chequebook/factory_test.go index 5105de182d3..d7223330ea4 100644 --- a/pkg/settlement/swap/chequebook/factory_test.go +++ b/pkg/settlement/swap/chequebook/factory_test.go @@ -7,7 +7,6 @@ package chequebook_test import ( "context" "errors" - "fmt" "math/big" "testing" @@ -31,19 +30,14 @@ func TestFactoryERC20Address(t *testing.T) { factoryAddress := common.HexToAddress("0xabcd") erc20Address := common.HexToAddress("0xeffff") - factory := chequebook.NewFactory( - backendmock.New(), - transactionmock.New( - transactionmock.WithABICall( - &factoryABI, - factoryAddress, - common.BytesToHash(erc20Address.Bytes()).Bytes(), - "ERC20Address", - ), + factory := chequebook.NewFactory(backendmock.New(), transactionmock.New( + transactionmock.WithABICall( + &factoryABI, + factoryAddress, + common.BytesToHash(erc20Address.Bytes()).Bytes(), + "ERC20Address", ), - factoryAddress, - nil, - ) + ), factoryAddress) addr, err := factory.ERC20Address(context.Background()) if err != nil { @@ -55,204 +49,29 @@ func TestFactoryERC20Address(t *testing.T) { } } -func backendWithCodeAt(codeMap map[common.Address]string) transaction.Backend { - return backendmock.New( - backendmock.WithCodeAtFunc(func(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error) { - code, ok := codeMap[contract] - if !ok { - return nil, fmt.Errorf("called with wrong address. wanted one of %v, got %x", codeMap, contract) - } - if blockNumber != nil { - return nil, errors.New("not called for latest block") - } - return common.FromHex(code), nil - }), - ) -} - -func TestFactoryVerifySelf(t *testing.T) { - t.Parallel() - - factoryAddress := common.HexToAddress("0xabcd") - legacyFactory1 := common.HexToAddress("0xbbbb") - legacyFactory2 := common.HexToAddress("0xcccc") - - t.Run("valid", func(t *testing.T) { - t.Parallel() - - factory := chequebook.NewFactory( - backendWithCodeAt(map[common.Address]string{ - factoryAddress: sw3abi.SimpleSwapFactoryDeployedBinv0_6_5, - legacyFactory1: sw3abi.SimpleSwapFactoryDeployedBinv0_6_5, - legacyFactory2: sw3abi.SimpleSwapFactoryDeployedBinv0_6_5, - }), - transactionmock.New(), - factoryAddress, - []common.Address{legacyFactory1, legacyFactory2}, - ) - - err := factory.VerifyBytecode(context.Background()) - if err != nil { - t.Fatal(err) - } - }) - - t.Run("invalid deploy factory", func(t *testing.T) { - t.Parallel() - - factory := chequebook.NewFactory( - backendWithCodeAt(map[common.Address]string{ - factoryAddress: "abcd", - }), - transactionmock.New(), - factoryAddress, - nil, - ) - - err := factory.VerifyBytecode(context.Background()) - if err == nil { - t.Fatal("verified invalid factory") - } - if !errors.Is(err, chequebook.ErrInvalidFactory) { - t.Fatalf("wrong error. wanted %v, got %v", chequebook.ErrInvalidFactory, err) - } - }) - - t.Run("invalid legacy factories", func(t *testing.T) { - t.Parallel() - - factory := chequebook.NewFactory( - backendWithCodeAt(map[common.Address]string{ - factoryAddress: sw3abi.SimpleSwapFactoryDeployedBinv0_6_5, - legacyFactory1: sw3abi.SimpleSwapFactoryDeployedBinv0_6_5, - legacyFactory2: "abcd", - }), - transactionmock.New(), - factoryAddress, - []common.Address{legacyFactory1, legacyFactory2}, - ) - - err := factory.VerifyBytecode(context.Background()) - if err == nil { - t.Fatal("verified invalid factory") - } - if !errors.Is(err, chequebook.ErrInvalidFactory) { - t.Fatalf("wrong error. wanted %v, got %v", chequebook.ErrInvalidFactory, err) - } - }) -} - func TestFactoryVerifyChequebook(t *testing.T) { t.Parallel() factoryAddress := common.HexToAddress("0xabcd") chequebookAddress := common.HexToAddress("0xefff") - legacyFactory1 := common.HexToAddress("0xbbbb") - legacyFactory2 := common.HexToAddress("0xcccc") t.Run("valid", func(t *testing.T) { t.Parallel() - factory := chequebook.NewFactory( - backendmock.New(), - transactionmock.New( - transactionmock.WithABICall( - &factoryABI, - factoryAddress, - common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"), - "deployedContracts", - chequebookAddress, - ), + factory := chequebook.NewFactory(backendmock.New(), transactionmock.New( + transactionmock.WithABICall( + &factoryABI, + factoryAddress, + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"), + "deployedContracts", + chequebookAddress, ), - factoryAddress, - []common.Address{legacyFactory1, legacyFactory2}, - ) + ), factoryAddress) err := factory.VerifyChequebook(context.Background(), chequebookAddress) if err != nil { t.Fatal(err) } }) - - t.Run("valid legacy", func(t *testing.T) { - t.Parallel() - - factory := chequebook.NewFactory( - backendmock.New(), - transactionmock.New( - transactionmock.WithABICallSequence( - transactionmock.ABICall( - &factoryABI, - factoryAddress, - common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000"), - "deployedContracts", - chequebookAddress, - ), - transactionmock.ABICall( - &factoryABI, - legacyFactory1, - common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000"), - "deployedContracts", - chequebookAddress, - ), - transactionmock.ABICall( - &factoryABI, - legacyFactory2, - common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"), - "deployedContracts", - chequebookAddress, - ), - )), - factoryAddress, - []common.Address{legacyFactory1, legacyFactory2}, - ) - - err := factory.VerifyChequebook(context.Background(), chequebookAddress) - if err != nil { - t.Fatal(err) - } - }) - - t.Run("invalid", func(t *testing.T) { - t.Parallel() - - factory := chequebook.NewFactory( - backendmock.New(), - transactionmock.New( - transactionmock.WithABICallSequence( - transactionmock.ABICall( - &factoryABI, - factoryAddress, - common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000"), - "deployedContracts", - chequebookAddress, - ), - transactionmock.ABICall( - &factoryABI, - legacyFactory1, - common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000"), - "deployedContracts", - chequebookAddress, - ), - transactionmock.ABICall( - &factoryABI, - legacyFactory2, - common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000"), - "deployedContracts", - chequebookAddress, - ), - )), - factoryAddress, - []common.Address{legacyFactory1, legacyFactory2}, - ) - - err := factory.VerifyChequebook(context.Background(), chequebookAddress) - if err == nil { - t.Fatal("verified invalid chequebook") - } - if !errors.Is(err, chequebook.ErrNotDeployedByFactory) { - t.Fatalf("wrong error. wanted %v, got %v", chequebook.ErrNotDeployedByFactory, err) - } - }) } func TestFactoryDeploy(t *testing.T) { @@ -265,36 +84,31 @@ func TestFactoryDeploy(t *testing.T) { deployAddress := common.HexToAddress("0xdddd") nonce := common.HexToHash("eeff") - factory := chequebook.NewFactory( - backendmock.New(), - transactionmock.New( - transactionmock.WithABISend(&factoryABI, deployTransactionHash, factoryAddress, big.NewInt(0), "deploySimpleSwap", issuerAddress, defaultTimeout, nonce), - transactionmock.WithWaitForReceiptFunc(func(ctx context.Context, txHash common.Hash) (receipt *types.Receipt, err error) { - if txHash != deployTransactionHash { - t.Fatalf("waiting for wrong transaction. wanted %x, got %x", deployTransactionHash, txHash) - } - logData, err := simpleSwapDeployedEvent.Inputs.NonIndexed().Pack(deployAddress) - if err != nil { - t.Fatal(err) - } - return &types.Receipt{ - Status: 1, - Logs: []*types.Log{ - { - Data: logData, - }, - { - Address: factoryAddress, - Topics: []common.Hash{simpleSwapDeployedEvent.ID}, - Data: logData, - }, + factory := chequebook.NewFactory(backendmock.New(), transactionmock.New( + transactionmock.WithABISend(&factoryABI, deployTransactionHash, factoryAddress, big.NewInt(0), "deploySimpleSwap", issuerAddress, defaultTimeout, nonce), + transactionmock.WithWaitForReceiptFunc(func(ctx context.Context, txHash common.Hash) (receipt *types.Receipt, err error) { + if txHash != deployTransactionHash { + t.Fatalf("waiting for wrong transaction. wanted %x, got %x", deployTransactionHash, txHash) + } + logData, err := simpleSwapDeployedEvent.Inputs.NonIndexed().Pack(deployAddress) + if err != nil { + t.Fatal(err) + } + return &types.Receipt{ + Status: 1, + Logs: []*types.Log{ + { + Data: logData, }, - }, nil - }, - )), - factoryAddress, - nil, - ) + { + Address: factoryAddress, + Topics: []common.Hash{simpleSwapDeployedEvent.ID}, + Data: logData, + }, + }, + }, nil + }, + )), factoryAddress) txHash, err := factory.Deploy(context.Background(), issuerAddress, defaultTimeout, nonce) if err != nil { @@ -320,21 +134,16 @@ func TestFactoryDeployReverted(t *testing.T) { factoryAddress := common.HexToAddress("0xabcd") deployTransactionHash := common.HexToHash("0xffff") - factory := chequebook.NewFactory( - backendmock.New(), - transactionmock.New( - transactionmock.WithWaitForReceiptFunc(func(ctx context.Context, txHash common.Hash) (receipt *types.Receipt, err error) { - if txHash != deployTransactionHash { - t.Fatalf("waiting for wrong transaction. wanted %x, got %x", deployTransactionHash, txHash) - } - return &types.Receipt{ - Status: 0, - }, nil - }), - ), - factoryAddress, - nil, - ) + factory := chequebook.NewFactory(backendmock.New(), transactionmock.New( + transactionmock.WithWaitForReceiptFunc(func(ctx context.Context, txHash common.Hash) (receipt *types.Receipt, err error) { + if txHash != deployTransactionHash { + t.Fatalf("waiting for wrong transaction. wanted %x, got %x", deployTransactionHash, txHash) + } + return &types.Receipt{ + Status: 0, + }, nil + }), + ), factoryAddress) _, err := factory.WaitDeployed(context.Background(), deployTransactionHash) if err == nil { diff --git a/pkg/settlement/swap/chequebook/init.go b/pkg/settlement/swap/chequebook/init.go index b8b21f154bb..19bfc3c56b0 100644 --- a/pkg/settlement/swap/chequebook/init.go +++ b/pkg/settlement/swap/chequebook/init.go @@ -133,12 +133,6 @@ func Init( ) (chequebookService Service, err error) { logger = logger.WithName(loggerName).Register() - // verify that the supplied factory is valid - err = chequebookFactory.VerifyBytecode(ctx) - if err != nil { - return nil, err - } - var chequebookAddress common.Address err = stateStore.Get(chequebookKey, &chequebookAddress) if err != nil {