fix: zero out gas limit

This commit is contained in:
Dirk McCormick 2020-07-22 13:55:31 -04:00
parent d70edbcb7c
commit 46b7546d51
3 changed files with 36 additions and 16 deletions

View File

@ -9,6 +9,9 @@ import (
"testing"
"time"
"github.com/filecoin-project/lotus/api"
"github.com/ipfs/go-cid"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/events"
@ -72,10 +75,8 @@ func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) {
if err != nil {
t.Fatal(err)
}
res, err := paymentCreator.StateWaitMsg(ctx, channelInfo.ChannelMessage, 1)
if res.Receipt.ExitCode != 0 {
t.Fatal("did not successfully create payment channel")
}
res := waitForMessage(ctx, t, paymentCreator, channelInfo.ChannelMessage, time.Second, "channel create")
var params initactor.ExecReturn
err = params.UnmarshalCBOR(bytes.NewReader(res.Receipt.Return))
if err != nil {
@ -123,10 +124,8 @@ func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) {
if err != nil {
t.Fatal(err)
}
res, err = paymentCreator.StateWaitMsg(ctx, settleMsgCid, 1)
if err != nil {
t.Fatal(err)
}
res = waitForMessage(ctx, t, paymentCreator, settleMsgCid, time.Second, "settle")
if res.Receipt.ExitCode != 0 {
t.Fatal("Unable to settle payment channel")
}
@ -158,7 +157,11 @@ func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) {
return preds.OnPaymentChannelActorChanged(channel, preds.OnToSendAmountChanges())(ctx, oldTs.Key(), newTs.Key())
})
<-finished
select {
case <-finished:
case <-time.After(time.Second):
t.Fatal("Timed out waiting for receiver to submit vouchers")
}
// collect funds (from receiver, though either party can do it)
collectMsg, err := paymentReceiver.PaychCollect(ctx, channel)
@ -193,6 +196,23 @@ func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) {
bm.stop()
}
func waitForMessage(ctx context.Context, t *testing.T, paymentCreator TestNode, msgCid cid.Cid, duration time.Duration, desc string) *api.MsgLookup {
ctx, cancel := context.WithTimeout(ctx, duration)
defer cancel()
fmt.Println("Waiting for", desc)
res, err := paymentCreator.StateWaitMsg(ctx, msgCid, 1)
if err != nil {
fmt.Println("Error waiting for", desc, err)
t.Fatal(err)
}
if res.Receipt.ExitCode != 0 {
t.Fatal("did not successfully send %s", desc)
}
fmt.Println("Confirmed", desc)
return res
}
type blockMiner struct {
ctx context.Context
t *testing.T
@ -243,8 +263,8 @@ func sendFunds(ctx context.Context, t *testing.T, sender TestNode, addr address.
From: senderAddr,
To: addr,
Value: amount,
GasLimit: 100_000_000,
GasPrice: abi.NewTokenAmount(1000),
GasLimit: 0,
GasPrice: abi.NewTokenAmount(0),
}
sm, err := sender.MpoolPushMessage(ctx, msg)

View File

@ -161,7 +161,7 @@ func (a *PaychAPI) PaychCollect(ctx context.Context, addr address.Address) (cid.
Method: builtin.MethodsPaych.Collect,
Nonce: nonce,
GasLimit: 100_000_000,
GasLimit: 0,
GasPrice: types.NewInt(0),
}

View File

@ -185,7 +185,7 @@ func (pm *Manager) checkVoucherValid(ctx context.Context, ch address.Address, sv
// CheckVoucherSpendable checks if the given voucher is currently spendable
func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) {
owner, err := pm.getPaychOwner(ctx, ch)
recipient, err := pm.getPaychRecipient(ctx, ch)
if err != nil {
return false, err
}
@ -222,7 +222,7 @@ func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address
}
ret, err := pm.sm.Call(ctx, &types.Message{
From: owner,
From: recipient,
To: ch,
Method: builtin.MethodsPaych.UpdateChannelState,
Params: enc,
@ -238,13 +238,13 @@ func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address
return true, nil
}
func (pm *Manager) getPaychOwner(ctx context.Context, ch address.Address) (address.Address, error) {
func (pm *Manager) getPaychRecipient(ctx context.Context, ch address.Address) (address.Address, error) {
var state paych.State
if _, err := pm.sm.LoadActorState(ctx, ch, &state, nil); err != nil {
return address.Address{}, err
}
return state.From, nil
return state.To, nil
}
func (pm *Manager) AddVoucher(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) {