Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Add test vector generation into ApplyMessage calls #1432

Merged
merged 6 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,19 @@ jobs:
- run:
name: "Ensure we don't need to run 'make gen'"
command: |
make gen && go mod tidy && git diff --exit-code
make gen && go mod tidy && git diff --exit-code
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why go.sum was changing in between but it was and causing failures on ci


check-determinism:
executor: golang
steps:
- install-deps
- prepare
- go/mod-download
- run:
name: "Check for execution determinism"
command: make determinism-check
- store_artifacts:
path: specs-actors

test-all:
executor: golang
Expand Down Expand Up @@ -127,3 +139,4 @@ workflows:
- build-all
- test-all
- check-gen
- check-determinism
26 changes: 25 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
GO_BIN ?= go
all: build lint test tidy
# relative path ../../ is included in path because current working directory of tests is directory of test files
# and all test vector generation comes from a call to go test ./actors/test
TEST_VECTOR_PATH = ../../test-vectors
all: build lint test tidy determinism-check
.PHONY: all

build:
Expand Down Expand Up @@ -27,6 +30,27 @@ gen:
$(GO_BIN) run ./gen/gen.go
.PHONY: gen

determinism-check:
rm -rf test-vectors/determinism

SPECS_ACTORS_DETERMINISM="$(TEST_VECTOR_PATH)/determinism" $(GO_BIN) test ./actors/test -count=1
$(GO_BIN) build ./test-vectors/tools/digest

if [ "`./digest ./test-vectors/determinism`" != "`cat ./test-vectors/determinism-check`" ]; then \
echo "test-vectors don't match expected";\
exit 1;\
fi

determinism-gen:
rm -rf test-vectors/determinism
SPECS_ACTORS_DETERMINISM="$(TEST_VECTOR_PATH)/determinism" $(GO_BIN) test ./actors/test -count=1
$(GO_BIN) build ./test-vectors/tools/digest
./digest ./test-vectors/determinism > ./test-vectors/determinism-check

conformance-gen:
rm -rf test-vectors/conformance
SPECS_ACTORS_CONFORMANCE="$(TEST_VECTOR_PATH)/conformance" $(GO_BIN) test ./actors/test -count=1
tar -zcf test-vectors/conformance.tar.gz test-vectors/conformance

# tools
toolspath:=support/tools
Expand Down
17 changes: 8 additions & 9 deletions actors/test/commit_post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ func TestCommitPoStFlow(t *testing.T) {
PoStProof: abi.RegisteredPoStProof_StackedDrgWindow32GiBV1,
}},
ChainCommitEpoch: dlInfo.Challenge,
ChainCommitRand: []byte("not really random"),
ChainCommitRand: []byte(vm.RandString),
}
// PoSt is rejected for skipping all sectors.
result := tv.ApplyMessage(addrs[0], minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.SubmitWindowedPoSt, &submitParams)
result := vm.RequireApplyMessage(t, tv, addrs[0], minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.SubmitWindowedPoSt, &submitParams, t.Name())
assert.Equal(t, exitcode.ErrIllegalArgument, result.Code)

vm.ExpectInvocation{
Expand Down Expand Up @@ -562,7 +562,6 @@ func TestAggregateOnePreCommitExpires(t *testing.T) {
ctx := context.Background()
blkStore := ipld.NewBlockStoreInMemory()
v := vm.NewVMWithSingletons(ctx, t, blkStore)

sealProof := abi.RegisteredSealProof_StackedDrg32GiBV1_1
wPoStProof, err := sealProof.RegisteredWindowPoStProof()
require.NoError(t, err)
Expand Down Expand Up @@ -667,15 +666,15 @@ func TestAggregateSizeLimits(t *testing.T) {
proveCommitAggregateTooManyParams := miner.ProveCommitAggregateParams{
SectorNumbers: sectorNosBf,
}
res := v.ApplyMessage(addrs[0], minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.ProveCommitAggregate, &proveCommitAggregateTooManyParams)
res := vm.RequireApplyMessage(t, v, addrs[0], minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.ProveCommitAggregate, &proveCommitAggregateTooManyParams, t.Name())
assert.Equal(t, exitcode.ErrIllegalArgument, res.Code) // fail with too many aggregates

// Fail with too few sectors
tooFewSectorNosBf := precommitSectorNumbers(precommits[:miner.MinAggregatedSectors-1])
proveCommitAggregateTooFewParams := miner.ProveCommitAggregateParams{
SectorNumbers: tooFewSectorNosBf,
}
res = v.ApplyMessage(addrs[0], minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.ProveCommitAggregate, &proveCommitAggregateTooFewParams)
res = vm.RequireApplyMessage(t, v, addrs[0], minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.ProveCommitAggregate, &proveCommitAggregateTooFewParams, t.Name())
assert.Equal(t, exitcode.ErrIllegalArgument, res.Code)

// Fail with proof too big
Expand All @@ -684,7 +683,7 @@ func TestAggregateSizeLimits(t *testing.T) {
SectorNumbers: justRightSectorNosBf,
AggregateProof: make([]byte, miner.MaxAggregateProofSize+1),
}
res = v.ApplyMessage(addrs[0], minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.ProveCommitAggregate, &proveCommitAggregateTooBigProofParams)
res = vm.RequireApplyMessage(t, v, addrs[0], minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.ProveCommitAggregate, &proveCommitAggregateTooBigProofParams, t.Name())
assert.Equal(t, exitcode.ErrIllegalArgument, res.Code)
}

Expand Down Expand Up @@ -726,7 +725,7 @@ func TestAggregateBadSender(t *testing.T) {
proveCommitAggregateParams := miner.ProveCommitAggregateParams{
SectorNumbers: sectorNosBf,
}
res := v.ApplyMessage(addrs[1], minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.ProveCommitAggregate, &proveCommitAggregateParams)
res := vm.RequireApplyMessage(t, v, addrs[1], minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.ProveCommitAggregate, &proveCommitAggregateParams, t.Name())
assert.Equal(t, exitcode.ErrForbidden, res.Code)
}

Expand Down Expand Up @@ -773,7 +772,7 @@ func TestAggregateBadSectorNumber(t *testing.T) {
proveCommitAggregateTooManyParams := miner.ProveCommitAggregateParams{
SectorNumbers: sectorNosBf,
}
res := v.ApplyMessage(addrs[0], minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.ProveCommitAggregate, &proveCommitAggregateTooManyParams)
res := vm.RequireApplyMessage(t, v, addrs[0], minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.ProveCommitAggregate, &proveCommitAggregateTooManyParams, t.Name())
assert.Equal(t, exitcode.ErrIllegalArgument, res.Code)
}

Expand Down Expand Up @@ -964,7 +963,7 @@ func submitWindowPoSt(t *testing.T, v *vm.VM, worker, actor address.Address, dlI
PoStProof: abi.RegisteredPoStProof_StackedDrgWindow32GiBV1,
}},
ChainCommitEpoch: dlInfo.Challenge,
ChainCommitRand: []byte("not really random"),
ChainCommitRand: []byte(vm.RandString),
}
vm.ApplyOk(t, v, worker, actor, big.Zero(), builtin.MethodsMiner.SubmitWindowedPoSt, &submitParams)

Expand Down
8 changes: 4 additions & 4 deletions actors/test/committed_capacity_scenario_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestReplaceCommittedCapacitySectorWithDealLadenSector(t *testing.T) {
PoStProof: abi.RegisteredPoStProof_StackedDrgWindow32GiBV1,
}},
ChainCommitEpoch: dlInfo.Challenge,
ChainCommitRand: []byte("not really random"),
ChainCommitRand: []byte(vm.RandString),
}

vm.ApplyOk(t, v, addrs[0], minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.SubmitWindowedPoSt, &submitParams)
Expand Down Expand Up @@ -319,7 +319,7 @@ func TestReplaceCommittedCapacitySectorWithDealLadenSector(t *testing.T) {
PoStProof: abi.RegisteredPoStProof_StackedDrgWindow32GiBV1,
}},
ChainCommitEpoch: dlInfo.Challenge,
ChainCommitRand: []byte("not really random"),
ChainCommitRand: []byte(vm.RandString),
}
vm.ApplyOk(t, tv, worker, minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.SubmitWindowedPoSt, &submitParams)

Expand Down Expand Up @@ -353,7 +353,7 @@ func TestReplaceCommittedCapacitySectorWithDealLadenSector(t *testing.T) {
PoStProof: abi.RegisteredPoStProof_StackedDrgWindow32GiBV1,
}},
ChainCommitEpoch: dlInfo.Challenge,
ChainCommitRand: []byte("not really random"),
ChainCommitRand: []byte(vm.RandString),
}
vm.ApplyOk(t, tv, worker, minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.SubmitWindowedPoSt, &submitParams)

Expand Down Expand Up @@ -383,7 +383,7 @@ func TestReplaceCommittedCapacitySectorWithDealLadenSector(t *testing.T) {
PoStProof: abi.RegisteredPoStProof_StackedDrgWindow32GiBV1,
}},
ChainCommitEpoch: dlInfo.Challenge,
ChainCommitRand: []byte("not really random"),
ChainCommitRand: []byte(vm.RandString),
}
vm.ApplyOk(t, v, worker, minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.SubmitWindowedPoSt, &submitParams)

Expand Down
2 changes: 1 addition & 1 deletion actors/test/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func publishDeal(t *testing.T, v *vm.VM, provider, dealClient, minerID addr.Addr
},
}},
}
result := v.ApplyMessage(provider, builtin.StorageMarketActorAddr, big.Zero(), builtin.MethodsMarket.PublishStorageDeals, &publishDealParams)
result := vm.RequireApplyMessage(t, v, provider, builtin.StorageMarketActorAddr, big.Zero(), builtin.MethodsMarket.PublishStorageDeals, &publishDealParams, t.Name())
require.Equal(t, exitcode.Ok, result.Code)

expectedPublishSubinvocations := []vm.ExpectInvocation{
Expand Down
2 changes: 1 addition & 1 deletion actors/test/cron_catches_expiries_scenario_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/filecoin-project/specs-actors/v5/support/vm"
)

var fakeChainRandomness = []byte("not really random")
var fakeChainRandomness = []byte(vm.RandString)

func TestCronCatchedCCExpirationsAtDeadlineBoundary(t *testing.T) {
ctx := context.Background()
Expand Down
9 changes: 4 additions & 5 deletions actors/test/multisig_delete_self_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestMultisigDeleteSelf2Of3RemovedIsProposer(t *testing.T) {
vm.ApplyOk(t, v, addrs[1], multisigAddr, big.Zero(), builtin.MethodsMultisig.Approve, &approveRemoveSignerParams)

// txnid not found when third approval gets processed indicating that the transaction has gone through successfully
result := v.ApplyMessage(addrs[2], multisigAddr, big.Zero(), builtin.MethodsMultisig.Approve, &approveRemoveSignerParams)
result := vm.RequireApplyMessage(t, v, addrs[2], multisigAddr, big.Zero(), builtin.MethodsMultisig.Approve, &approveRemoveSignerParams, t.Name())
assert.Equal(t, exitcode.ErrNotFound, result.Code)

}
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestMultisigDeleteSelf2Of3RemovedIsApprover(t *testing.T) {
vm.ApplyOk(t, v, addrs[0], multisigAddr, big.Zero(), builtin.MethodsMultisig.Approve, &approveRemoveSignerParams)

// txnid not found when third approval gets processed indicating that the transaction has gone through successfully
result := v.ApplyMessage(addrs[2], multisigAddr, big.Zero(), builtin.MethodsMultisig.Approve, &approveRemoveSignerParams)
result := vm.RequireApplyMessage(t, v, addrs[2], multisigAddr, big.Zero(), builtin.MethodsMultisig.Approve, &approveRemoveSignerParams, t.Name())
assert.Equal(t, exitcode.ErrNotFound, result.Code)

}
Expand All @@ -124,7 +124,6 @@ func TestMultisigDeleteSelf2Of2(t *testing.T) {
ctx := context.Background()
v := vm.NewVMWithSingletons(ctx, t, ipld.NewBlockStoreInMemory())
addrs := vm.CreateAccounts(ctx, t, v, 2, big.Mul(big.NewInt(10_000), big.NewInt(1e18)), 93837778)

multisigParams := multisig.ConstructorParams{
Signers: addrs,
NumApprovalsThreshold: 2,
Expand All @@ -138,7 +137,7 @@ func TestMultisigDeleteSelf2Of2(t *testing.T) {
CodeCID: builtin.MultisigActorCodeID,
ConstructorParams: paramBuf.Bytes(),
}
ret := vm.ApplyOk(t, v, addrs[0], builtin.InitActorAddr, big.Zero(), builtin.MethodsPower.CreateMiner, &initParam)
ret := vm.ApplyOk(t, v, addrs[0], builtin.InitActorAddr, big.Zero(), builtin.MethodsInit.Exec, &initParam)
initRet := ret.(*init_.ExecReturn)
assert.NotNil(t, initRet)
multisigAddr := initRet.IDAddress
Expand All @@ -165,7 +164,7 @@ func TestMultisigDeleteSelf2Of2(t *testing.T) {
vm.ApplyOk(t, v, addrs[1], multisigAddr, big.Zero(), builtin.MethodsMultisig.Approve, &approveRemoveSignerParams)

// txnid not found when another approval gets processed indicating that the transaction has gone through successfully
result := v.ApplyMessage(addrs[1], multisigAddr, big.Zero(), builtin.MethodsMultisig.Approve, &approveRemoveSignerParams)
result := vm.RequireApplyMessage(t, v, addrs[1], multisigAddr, big.Zero(), builtin.MethodsMultisig.Approve, &approveRemoveSignerParams, t.Name())
assert.Equal(t, exitcode.ErrNotFound, result.Code)
}

Expand Down
3 changes: 1 addition & 2 deletions actors/test/terminate_sectors_scenario_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TestTerminateSectors(t *testing.T) {
WindowPoStProofType: abi.RegisteredPoStProof_StackedDrgWindow32GiBV1,
Peer: abi.PeerID("not really a peer id"),
})

minerAddrs, ok := ret.(*power.CreateMinerReturn)
require.True(t, ok)

Expand Down Expand Up @@ -125,7 +124,7 @@ func TestTerminateSectors(t *testing.T) {
PoStProof: abi.RegisteredPoStProof_StackedDrgWindow32GiBV1,
}},
ChainCommitEpoch: dlInfo.Challenge,
ChainCommitRand: []byte("not really random"),
ChainCommitRand: []byte(vm.RandString),
})

// proving period cron adds miner power
Expand Down
2 changes: 2 additions & 0 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ func main() {

if err := gen.WriteTupleEncodersToFile("./support/vm/cbor_gen.go", "vm",
vm.ChainMessage{},
vm.StateInfo0{},
vm.StateRoot{},
); err != nil {
panic(err)
}
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ require (
github.com/ipfs/go-block-format v0.0.3
github.com/ipfs/go-cid v0.0.7
github.com/ipfs/go-ipld-cbor v0.0.5
github.com/ipfs/go-ipld-format v0.0.2
github.com/ipld/go-car v0.1.0
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
github.com/minio/sha256-simd v0.1.1
github.com/multiformats/go-multihash v0.0.14
Expand All @@ -23,6 +25,6 @@ require (
github.com/whyrusleeping/cbor-gen v0.0.0-20210118024343-169e9d70c0c2
github.com/xorcare/golden v0.6.0
golang.org/x/sync v0.0.0-20190423024810-112230192c58
golang.org/x/text v0.3.0
golang.org/x/text v0.3.2
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
)
Loading