Skip to content

Commit

Permalink
fix(market): save resources offer to the bid
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Nov 15, 2023
1 parent 01363ef commit 3b5de8f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
9 changes: 6 additions & 3 deletions x/market/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,9 @@ func TestCloseBidUnknownOrder(t *testing.T) {
orderID := types.MakeOrderID(group.ID(), 1)
provider := testutil.AccAddress(t)
price := sdk.NewDecCoin(testutil.CoinDenom, sdk.NewInt(int64(rand.Uint16())))
roffer := types.ResourceOfferFromRU(group.GroupSpec.Resources)

bid, err := suite.MarketKeeper().CreateBid(suite.Context(), orderID, provider, price)
bid, err := suite.MarketKeeper().CreateBid(suite.Context(), orderID, provider, price, roffer)
require.NoError(t, err)

suite.MarketKeeper().CreateLease(suite.Context(), bid)
Expand Down Expand Up @@ -418,10 +419,12 @@ func (st *testSuite) createLease() (types.LeaseID, types.Bid, types.Order) {

func (st *testSuite) createBid() (types.Bid, types.Order) {
st.t.Helper()
order, _ := st.createOrder(testutil.Resources(st.t))
order, gspec := st.createOrder(testutil.Resources(st.t))
provider := testutil.AccAddress(st.t)
price := sdk.NewDecCoin(testutil.CoinDenom, sdk.NewInt(int64(rand.Uint16())))
bid, err := st.MarketKeeper().CreateBid(st.Context(), order.ID(), provider, price)
roffer := types.ResourceOfferFromRU(gspec.Resources)

bid, err := st.MarketKeeper().CreateBid(st.Context(), order.ID(), provider, price, roffer)
require.NoError(st.t, err)
require.Equal(st.t, order.ID(), bid.ID().OrderID())
require.Equal(st.t, price, bid.Price)
Expand Down
2 changes: 1 addition & 1 deletion x/market/handler/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (ms msgServer) CreateBid(goCtx context.Context, msg *types.MsgCreateBid) (*
return nil, types.ErrCapabilitiesMismatch
}

bid, err := ms.keepers.Market.CreateBid(ctx, msg.Order, provider, msg.Price)
bid, err := ms.keepers.Market.CreateBid(ctx, msg.Order, provider, msg.Price, msg.ResourcesOffer)
if err != nil {
return nil, err
}
Expand Down
14 changes: 7 additions & 7 deletions x/market/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type IKeeper interface {
Codec() codec.BinaryCodec
StoreKey() sdk.StoreKey
CreateOrder(ctx sdk.Context, gid dtypes.GroupID, spec dtypes.GroupSpec) (types.Order, error)
CreateBid(ctx sdk.Context, oid types.OrderID, provider sdk.AccAddress, price sdk.DecCoin) (types.Bid, error)
CreateBid(ctx sdk.Context, oid types.OrderID, provider sdk.AccAddress, price sdk.DecCoin, roffer types.ResourcesOffer) (types.Bid, error)
CreateLease(ctx sdk.Context, bid types.Bid)
OnOrderMatched(ctx sdk.Context, order types.Order)
OnBidMatched(ctx sdk.Context, bid types.Bid)
Expand Down Expand Up @@ -52,7 +52,6 @@ type Keeper struct {

// NewKeeper creates and returns an instance for Market keeper
func NewKeeper(cdc codec.BinaryCodec, skey sdk.StoreKey, pspace paramtypes.Subspace, ekeeper EscrowKeeper) IKeeper {

if !pspace.HasKeyTable() {
pspace = pspace.WithKeyTable(types.ParamKeyTable())
}
Expand Down Expand Up @@ -122,14 +121,15 @@ func (k Keeper) CreateOrder(ctx sdk.Context, gid dtypes.GroupID, spec dtypes.Gro
}

// CreateBid creates a bid for a order with given orderID, price for bid and provider
func (k Keeper) CreateBid(ctx sdk.Context, oid types.OrderID, provider sdk.AccAddress, price sdk.DecCoin) (types.Bid, error) {
func (k Keeper) CreateBid(ctx sdk.Context, oid types.OrderID, provider sdk.AccAddress, price sdk.DecCoin, roffer types.ResourcesOffer) (types.Bid, error) {
store := ctx.KVStore(k.skey)

bid := types.Bid{
BidID: types.MakeBidID(oid, provider),
State: types.BidOpen,
Price: price,
CreatedAt: ctx.BlockHeight(),
BidID: types.MakeBidID(oid, provider),
State: types.BidOpen,
Price: price,
CreatedAt: ctx.BlockHeight(),
ResourcesOffer: roffer,
}

key := keys.BidKey(bid.ID())
Expand Down
6 changes: 4 additions & 2 deletions x/market/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,12 @@ func createLease(t testing.TB, suite *state.TestSuite) types.LeaseID {
func createBid(t testing.TB, suite *state.TestSuite) (types.Bid, types.Order) {
t.Helper()
ctx := suite.Context()
order, _ := createOrder(t, suite.Context(), suite.MarketKeeper())
order, gspec := createOrder(t, suite.Context(), suite.MarketKeeper())
provider := testutil.AccAddress(t)
price := testutil.AkashDecCoinRandom(t)
bid, err := suite.MarketKeeper().CreateBid(ctx, order.ID(), provider, price)
roffer := types.ResourceOfferFromRU(gspec.Resources)

bid, err := suite.MarketKeeper().CreateBid(ctx, order.ID(), provider, price, roffer)
require.NoError(t, err)
assert.Equal(t, order.ID(), bid.ID().OrderID())
assert.Equal(t, price, bid.Price)
Expand Down
4 changes: 3 additions & 1 deletion x/provider/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"

mtypes "github.com/akash-network/akash-api/go/node/market/v1beta4"
types "github.com/akash-network/akash-api/go/node/provider/v1beta3"

akashtypes "github.com/akash-network/akash-api/go/node/types/v1beta3"
Expand Down Expand Up @@ -234,8 +235,9 @@ func TestProviderUpdateAttributes(t *testing.T) {
require.NoError(t, err)

price := testutil.DecCoin(t)
roffer := mtypes.ResourceOfferFromRU(group.GroupSpec.Resources)

bid, err := suite.mkeeper.CreateBid(suite.ctx, order.ID(), addr, price)
bid, err := suite.mkeeper.CreateBid(suite.ctx, order.ID(), addr, price, roffer)
require.NoError(t, err)

suite.mkeeper.CreateLease(suite.ctx, bid)
Expand Down

0 comments on commit 3b5de8f

Please sign in to comment.