diff --git a/abci/example/orderbook/app.go b/abci/example/orderbook/app.go index ab14dbfd7..0132126fc 100644 --- a/abci/example/orderbook/app.go +++ b/abci/example/orderbook/app.go @@ -33,6 +33,7 @@ type StateMachine struct { } func New() *StateMachine { + StateMachine := StateMachine {} return &StateMachine{} } @@ -285,13 +286,12 @@ func (sm *StateMachine) ProcessProposal(req types.RequestProcessProposal) types. } case *Msg_MsgTradeSet: + // for each matched order + // check the accounts exist, that the signatures are valid and that they have the available funds to make the swap if err := m.MsgTradeSet.TradeSet.ValidateBasic(); err != nil { return rejectProposal() } - // for each matched order - // check the accounts exist, that the signatures are valid and that they have the available funds to make the swap - default: return rejectProposal() diff --git a/abci/example/orderbook/app_test.go b/abci/example/orderbook/app_test.go index 617777486..774506da7 100644 --- a/abci/example/orderbook/app_test.go +++ b/abci/example/orderbook/app_test.go @@ -1,16 +1,20 @@ package orderbook_test import ( - "fmt" "testing" - "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/abci/example/orderbook" + "github.com/tendermint/tendermint/abci/types" ) -func TestPrepareProposal(t *testing.T) { - // check to see if the market collected all of the pairs +func TestNew(t *testing.T) { + StateMachine := New() + // initialise market market := orderbook.NewMarket(testPair) - require.EqualValues(t, ) -} + // create transaction + response := S.PrepareProposal(types.RequestPrepareProposal{}) + // check to see if the market collected all of the pairs + // test to see if the tradeset is valid + // require.EqualValues(t, ) +} diff --git a/abci/example/orderbook/types.go b/abci/example/orderbook/types.go index bd1298360..7b168b115 100644 --- a/abci/example/orderbook/types.go +++ b/abci/example/orderbook/types.go @@ -39,7 +39,6 @@ func (msg *MsgAsk) ValidateBasic() error { return errors.New("invalid signature size") } - //quantity to be more than 0 // price to not be 0 @@ -92,26 +91,44 @@ func (p *Pair) ValidateBasic() error { func (o *OrderBid) ValidateBasic() error { if o.MaxQuantity == 0 { - return errors.New("quantity outbound must be non zero") + return errors.New("max quantity must be non zero") } if o.MaxPrice <= 0 { return errors.New("min price must be greater than 0") } - + return nil } +// check signatures are valid func (m *MatchedOrder) ValidateBasic() error { if len(m.OrderAsk.Signature) != ed25519.SignatureSize { return errors.New("invalid signature size") } + + if len(m.OrderBid.Signature) != ed25519.SignatureSize { + return errors.New("invalid signature size") + } + return nil } func (t *TradeSet) ValidateBasic() error { - return t.Pair.ValidateBasic() - return t.MatchedOrders.ValidateBasic() + for _, matchedOrder := range t.MatchedOrders { + if err := matchedOrder.ValidateBasic(); err != nil { + return err + } + // checking if there is an account + if matchedOrder.OrderAsk.OwnerId == 0 { + return errors.New("must have an owner id more than zero") + } + } + // validate the pairs are valid + if err := t.Pair.ValidateBasic(); err != nil { + return err + } + return nil } func (o *OrderAsk) ValidateBasic() error { @@ -133,4 +150,4 @@ func (a *Account) FindCommidity(denom string) *Commodity { } } return nil -} \ No newline at end of file +}