diff --git a/blockindex/sgd_indexer.go b/blockindex/sgd_indexer.go index 5fb1d31ecb..5bb73cbff4 100644 --- a/blockindex/sgd_indexer.go +++ b/blockindex/sgd_indexer.go @@ -444,6 +444,10 @@ func (sgd *sgdRegistry) CheckContract(ctx context.Context, contract string, heig } sgdIndex, err := sgd.getSGDIndex(addr.Bytes()) if err != nil { + // if the contract is not registered, return nil to prevent the evm from throwing error + if errors.Cause(err) == db.ErrNotExist || errors.Cause(err) == db.ErrBucketNotExist { + return nil, 0, false, nil + } return nil, 0, false, err } diff --git a/blockindex/sgd_indexer_test.go b/blockindex/sgd_indexer_test.go index 76e96f4401..da292eae1c 100644 --- a/blockindex/sgd_indexer_test.go +++ b/blockindex/sgd_indexer_test.go @@ -148,7 +148,7 @@ func TestNewSGDRegistry(t *testing.T) { blk := createTestingBlock(builder, 4, h, exec, logs) r.NoError(sgdRegistry.PutBlock(ctx, blk)) receiver, percentage, isApproved, err := sgdRegistry.CheckContract(ctx, registerAddress.String(), 4) - r.ErrorContains(err, "not exist in DB") + r.NoError(err) r.Nil(receiver) r.False(isApproved) hh, err := sgdRegistry.Height() diff --git a/e2etest/sgd_registry_test.go b/e2etest/sgd_registry_test.go index efa2c05ebd..fb21a2bb5b 100644 --- a/e2etest/sgd_registry_test.go +++ b/e2etest/sgd_registry_test.go @@ -177,7 +177,6 @@ func TestSGDRegistry(t *testing.T) { "c375c2ef0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4", }, checkContractExpect: checkContractExpectation{ - errorContains: "not exist in DB", contractAddress: registerAddress.String(), }, }, @@ -187,7 +186,6 @@ func TestSGDRegistry(t *testing.T) { "07f7aafb0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4", }, checkContractExpect: checkContractExpectation{ - errorContains: "not exist in DB", contractAddress: registerAddress.String(), }, }, @@ -225,7 +223,6 @@ func TestSGDRegistry(t *testing.T) { "07f7aafb0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4", }, checkContractExpect: checkContractExpectation{ - errorContains: "not exist in DB", contractAddress: registerAddress.String(), }, },