Fix MTransaction
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
parent
f19b8c82f4
commit
8e4661e6d2
@ -17,6 +17,7 @@ func init() {
|
||||
cbor.RegisterCborType(MultiSigSigner{})
|
||||
cbor.RegisterCborType(MultiSigSwapSignerParams{})
|
||||
cbor.RegisterCborType(MultiSigChangeReqParams{})
|
||||
cbor.RegisterCborType(MTransaction{})
|
||||
}
|
||||
|
||||
type MultiSigActor struct{}
|
||||
|
@ -1,15 +1,18 @@
|
||||
package actors_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.opencensus.io/trace"
|
||||
|
||||
"github.com/filecoin-project/go-lotus/chain/actors"
|
||||
"github.com/filecoin-project/go-lotus/chain/address"
|
||||
"github.com/filecoin-project/go-lotus/chain/types"
|
||||
"github.com/filecoin-project/go-lotus/chain/vm"
|
||||
"github.com/filecoin-project/go-lotus/tracing"
|
||||
)
|
||||
|
||||
func TestMultiSigCreate(t *testing.T) {
|
||||
@ -38,9 +41,15 @@ func ApplyOK(t testing.TB, ret *vm.ApplyRet) {
|
||||
}
|
||||
|
||||
func TestMultiSigOps(t *testing.T) {
|
||||
je := tracing.SetupJaegerTracing("test")
|
||||
defer je.Flush()
|
||||
ctx, span := trace.StartSpan(context.Background(), "/test-"+t.Name())
|
||||
defer span.End()
|
||||
|
||||
var creatorAddr, sig1Addr, sig2Addr, outsideAddr address.Address
|
||||
var multSigAddr address.Address
|
||||
opts := []HarnessOpt{
|
||||
HarnessCtx(ctx),
|
||||
HarnessAddr(&creatorAddr, 10000),
|
||||
HarnessAddr(&sig1Addr, 10000),
|
||||
HarnessAddr(&sig2Addr, 10000),
|
||||
@ -54,14 +63,14 @@ func TestMultiSigOps(t *testing.T) {
|
||||
}),
|
||||
}
|
||||
|
||||
curVal := types.NewInt(2000)
|
||||
h := NewHarness2(t, opts...)
|
||||
{
|
||||
sendVal := types.NewInt(2000)
|
||||
ret, state := h.SendFunds(t, creatorAddr, multSigAddr, sendVal)
|
||||
ret, state := h.SendFunds(t, creatorAddr, multSigAddr, curVal)
|
||||
ApplyOK(t, ret)
|
||||
ms, err := state.GetActor(multSigAddr)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, sendVal, ms.Balance)
|
||||
assert.Equal(t, curVal, ms.Balance)
|
||||
}
|
||||
|
||||
{
|
||||
@ -72,9 +81,21 @@ func TestMultiSigOps(t *testing.T) {
|
||||
Value: sendVal,
|
||||
})
|
||||
ApplyOK(t, ret)
|
||||
var txIdParam actors.MultiSigTxID
|
||||
err := cbor.DecodeInto(ret.Return, &txIdParam.TxID)
|
||||
var txIDParam actors.MultiSigTxID
|
||||
err := cbor.DecodeInto(ret.Return, &txIDParam.TxID)
|
||||
assert.NoError(t, err, "decoding txid")
|
||||
ret, state := h.Invoke(t, sig1Addr, multSigAddr, actors.MultiSigMethods.Approve,
|
||||
txIDParam)
|
||||
ApplyOK(t, ret)
|
||||
curVal = types.BigSub(curVal, sendVal)
|
||||
|
||||
outAct, err := state.GetActor(outsideAddr)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, sendVal, outAct.Balance)
|
||||
|
||||
msAct, err := state.GetActor(multSigAddr)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, curVal, msAct.Balance)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -41,9 +41,10 @@ type Harness2 struct {
|
||||
Stage HarnessStage
|
||||
Nonces map[address.Address]uint64
|
||||
|
||||
bs blockstore.Blockstore
|
||||
vm *vm.VM
|
||||
cs *store.ChainStore
|
||||
ctx context.Context
|
||||
bs blockstore.Blockstore
|
||||
vm *vm.VM
|
||||
cs *store.ChainStore
|
||||
}
|
||||
|
||||
var HarnessMinerFunds = types.NewInt(1000000)
|
||||
@ -99,20 +100,28 @@ func HarnessActor(actor *address.Address, creator *address.Address, code cid.Cid
|
||||
|
||||
}
|
||||
|
||||
func HarnessCtx(ctx context.Context) HarnessOpt {
|
||||
return func(t testing.TB, h *Harness2) error {
|
||||
h.ctx = ctx
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func NewHarness2(t *testing.T, options ...HarnessOpt) *Harness2 {
|
||||
h := &Harness2{
|
||||
Stage: HarnessPreInit,
|
||||
Nonces: make(map[address.Address]uint64),
|
||||
}
|
||||
h.bs = bstore.NewBlockstore(dstore.NewMapDatastore())
|
||||
h.HI = HarnessInit{
|
||||
NAddrs: 1,
|
||||
Miner: blsaddr(0),
|
||||
Addrs: map[address.Address]types.BigInt{
|
||||
blsaddr(0): HarnessMinerFunds,
|
||||
HI: HarnessInit{
|
||||
NAddrs: 1,
|
||||
Miner: blsaddr(0),
|
||||
Addrs: map[address.Address]types.BigInt{
|
||||
blsaddr(0): HarnessMinerFunds,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
ctx: context.Background(),
|
||||
bs: bstore.NewBlockstore(dstore.NewMapDatastore()),
|
||||
}
|
||||
for _, opt := range options {
|
||||
err := opt(t, h)
|
||||
if err != nil {
|
||||
@ -152,7 +161,7 @@ func (h *Harness2) Apply(t testing.TB, msg types.Message) (*vm.ApplyRet, *state.
|
||||
h.Nonces[msg.From] = msg.Nonce + 1
|
||||
}
|
||||
|
||||
ret, err := h.vm.ApplyMessage(context.TODO(), &msg)
|
||||
ret, err := h.vm.ApplyMessage(h.ctx, &msg)
|
||||
if err != nil {
|
||||
t.Fatalf("Applying message: %+v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user