diff --git a/pkg/innerring/processors/balance/handlers_test.go b/pkg/innerring/processors/balance/handlers_test.go new file mode 100644 index 0000000000..3470fba2d2 --- /dev/null +++ b/pkg/innerring/processors/balance/handlers_test.go @@ -0,0 +1,90 @@ +package balance + +import ( + "testing" + "time" + + frostfscontract "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/frostfs" + balanceEvent "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event/balance" + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test" + "github.com/nspcc-dev/neo-go/pkg/util" + "github.com/stretchr/testify/require" +) + +func TestProcessorCallsFrostFSContractForLockEvent(t *testing.T) { + t.Parallel() + as := &testAlphabetState{ + isAlphabet: true, + } + conv := &testPresicionConverter{} + cl := &testFrostFSContractClient{} + bsc := util.Uint160{100} + + processor, err := New(&Params{ + Log: test.NewLogger(t, true), + PoolSize: 2, + FrostFSClient: cl, + BalanceSC: bsc, + AlphabetState: as, + Converter: conv, + }) + require.NoError(t, err, "failed to create processor") + + processor.handleLock(balanceEvent.Lock{}) + + for processor.pool.Running() > 0 { + time.Sleep(10 * time.Millisecond) + } + + require.Equal(t, 1, cl.chequeCalls, "invalid Cheque calls") +} + +func TestProcessorDoesntCallFrostFSContractIfNotAlphabet(t *testing.T) { + t.Parallel() + as := &testAlphabetState{} + conv := &testPresicionConverter{} + cl := &testFrostFSContractClient{} + bsc := util.Uint160{100} + + processor, err := New(&Params{ + Log: test.NewLogger(t, true), + PoolSize: 2, + FrostFSClient: cl, + BalanceSC: bsc, + AlphabetState: as, + Converter: conv, + }) + require.NoError(t, err, "failed to create processor") + + processor.handleLock(balanceEvent.Lock{}) + + for processor.pool.Running() > 0 { + time.Sleep(10 * time.Millisecond) + } + + require.Equal(t, 0, cl.chequeCalls, "invalid Cheque calls") +} + +type testAlphabetState struct { + isAlphabet bool +} + +func (s *testAlphabetState) IsAlphabet() bool { + return s.isAlphabet +} + +type testPresicionConverter struct { +} + +func (c *testPresicionConverter) ToFixed8(v int64) int64 { + return v +} + +type testFrostFSContractClient struct { + chequeCalls int +} + +func (c *testFrostFSContractClient) Cheque(p frostfscontract.ChequePrm) error { + c.chequeCalls++ + return nil +} diff --git a/pkg/innerring/processors/balance/processor.go b/pkg/innerring/processors/balance/processor.go index 7ae639e891..356754cfbc 100644 --- a/pkg/innerring/processors/balance/processor.go +++ b/pkg/innerring/processors/balance/processor.go @@ -25,11 +25,15 @@ type ( ToFixed8(int64) int64 } + FrostFSClient interface { + Cheque(p frostfscontract.ChequePrm) error + } + // Processor of events produced by balance contract in the morphchain. Processor struct { log *logger.Logger pool *ants.Pool - frostfsClient *frostfscontract.Client + frostfsClient FrostFSClient balanceSC util.Uint160 alphabetState AlphabetState converter PrecisionConverter @@ -39,7 +43,7 @@ type ( Params struct { Log *logger.Logger PoolSize int - FrostFSClient *frostfscontract.Client + FrostFSClient FrostFSClient BalanceSC util.Uint160 AlphabetState AlphabetState Converter PrecisionConverter