Skip to content

Commit

Permalink
Merge Develop (#855)
Browse files Browse the repository at this point in the history
* run tests in parallel (#824)

* Key revoked validation (#820)

* Revocation validation

* Revocation validation

* Review comments

* add rules (#821)

<This is intended as a guide when describing-reviewing pull requests for go-centrifuge>
Fixs #800.

* Feat(documents): validate transitions (#819)

Closes #802 and Closes #803

* Implement CollaboratorCanUpdate on Invoice and PO (#830)

Closes #805 and Closes #806

* Feat/integrate collab can update (#834)

* added method to Model

* validator

* test


* lint

* New Signature structure (#791)

* signature check

* tmp

* fix test

* signature

* fmt

* fix tests

* use repo

* fixes

* updating proto

* added setup back

* Feat/write acls receive doc (#840)

Fixes #838 

Also, removed creating identities in every test. this should improve our integration tests run time

Note: testworld tests that check for transition failures are disabled until #807 is done

* Update log for coredoc (#842)

* Update log for coredoc

* Update log for coredoc

* Review comments

* Merge

* Update deps

* Update deps

* minor

* Added Invalid Signature Tests (#784)

* Initial commit for invalid signature test cases

* Added invalid signature in the utility method

* Added test case for revoked key signature

* Fixed test case to use Alice key for signing document

* Refactored prepareCoreDocument helper method

* Refactored invalid signature test

* Added valid signature success test case

* Rebased with develop and fixed failing tests

* Fixed issue with converting time to protobuf Timestamp

* Fixed failing unit test for timestamp

* Adding signing purpose key back once revoked

* Refactored Add and Revoke signing key

* Added method to get signing key pair

* Fixed spacing issues with imports

* Added test case to send document with revoked signing key

* Resolved review comments

* Refactored waitTillStatus to getTransactionStatusAndMessage

* Added nil check for message in transaction

* Document consensus validations (#846)

* Document consensus validations

* timestamp validations done

* More validations

* fix test

* Fix tests

* Review comments

* transitionValidator integration: requestDocumentSignature (#841)

<This is intended as a guide when describing-reviewing pull requests for go-centrifuge>
Issue Link: closes #807.


Co-authored-by: Vedhavyas Singareddi <[email protected]>

* Nft sign + execute (#845)

* signature check

* tmp

* fix test

* signature

* fmt

* fix tests

* use repo

* fixes

* adding signature proof

* updating proto

* added setup back

* execute integration

* add setup

* new contract

* comments

* fix tw

* fix id test

* fix p2p test

*  Fix timestamp conversions (#850)

* Document consensus validations

* timestamp validations done

* More validations

* fix test

* Fix tests

* Fix timestamp conversions

* Review comments

* Gocelery update

* Fix logs

* Fix logging

* Secret as env (#852)

* move secret (#853)

* Adding cent prefix (#854)

* Fix identity concurrent creation (#848)

* WIP fix identity concurrent creation

* tests

* add factory check
  • Loading branch information
mikiquantum authored Mar 18, 2019
1 parent 7383995 commit a742b00
Show file tree
Hide file tree
Showing 87 changed files with 3,065 additions and 957 deletions.
22 changes: 19 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,29 @@ install:

jobs:
include:
- stage: test
- stage: "Tests"
name: "Linting"
script:
- make lint-check proto-lint proto-all gen-swagger generate format-go
- echo "Checking that prototool and format-go don't result in a modified git tree" && git diff --exit-code protobufs/gen
- ./build/scripts/test_wrapper.sh
- stage: "Tests"
name: "Unit and CMD tests"
script:
- ./build/scripts/test_wrapper.sh unit cmd
after_success:
- bash <(curl -s https://codecov.io/bash)
- stage: "Tests"
name: "Integration tests"
script:
- ./build/scripts/test_wrapper.sh integration
after_success:
- bash <(curl -s https://codecov.io/bash)
- stage: "Tests"
name: "Test world tests"
script:
- ./build/scripts/test_wrapper.sh testworld
after_success:
- bash <(curl -s https://codecov.io/bash)
- bash <(curl -s https://codecov.io/bash)
- stage: build_artifacts
if: (NOT type IN (pull_request)) AND ((branch = develop) OR (branch = master))
before_script:
Expand Down
12 changes: 6 additions & 6 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ required = ["github.com/centrifuge/centrifuge-ethereum-contracts", "github.com/r

[[constraint]]
name = "github.com/centrifuge/centrifuge-protobufs"
revision = "20c7fd5e4210e68d2a5662a8714d51ceeae031b8"
revision = "864a8ef4039324cebf3f23df115f50db12009d4c"

[[override]]
name = "github.com/centrifuge/centrifuge-ethereum-contracts"
revision = "be1a93f627115fcf9978a85c4b6b8f08adf87f35"
revision = "c5e55d16c4cfe058ca641d2a746a665f277f0c9f"

[[constraint]]
name = "github.com/Masterminds/semver"
Expand All @@ -44,7 +44,7 @@ required = ["github.com/centrifuge/centrifuge-ethereum-contracts", "github.com/r

[[constraint]]
name = "github.com/centrifuge/gocelery"
revision = "fb11151a227ae41660e15f6c10e2e22eb1556531"
revision = "98e4381dac54051f9a6cd6d4e0c2815d87f625d8"

[[override]]
name = "github.com/ethereum/go-ethereum"
Expand Down
12 changes: 8 additions & 4 deletions anchors/anchor_contract.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion anchors/anchor_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package anchors

import (
"context"
"time"

logging "github.com/ipfs/go-log"
)
Expand All @@ -11,8 +12,16 @@ var log = logging.Logger("anchorRepository")
// AnchorRepository defines a set of functions that can be
// implemented by any type that stores and retrieves the anchoring, and pre anchoring details.
type AnchorRepository interface {

// PreCommitAnchor will call the transaction PreCommit on the smart contract, to pre commit a document update
PreCommitAnchor(ctx context.Context, anchorID AnchorID, signingRoot DocumentRoot) (confirmations chan bool, err error)

// CommitAnchor will send a commit transaction to Ethereum.
CommitAnchor(ctx context.Context, anchorID AnchorID, documentRoot DocumentRoot, documentProofs [][32]byte) (chan bool, error)
GetDocumentRootOf(anchorID AnchorID) (DocumentRoot, error)

// GetAnchorData takes an anchorID and returns the corresponding documentRoot from the chain.
GetAnchorData(anchorID AnchorID) (docRoot DocumentRoot, anchoredTime time.Time, err error)

// HasValidPreCommit checks if the given anchorID has a valid pre-commit
HasValidPreCommit(anchorID AnchorID) bool
}
12 changes: 9 additions & 3 deletions anchors/anchor_repository_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/sha256"
"os"
"testing"
"time"

"github.com/centrifuge/go-centrifuge/anchors"
"github.com/centrifuge/go-centrifuge/bootstrap"
Expand Down Expand Up @@ -34,6 +35,7 @@ func TestMain(m *testing.M) {
}

func TestPreCommitAnchor_Integration(t *testing.T) {
t.Parallel()
anchorID := utils.RandomSlice(32)
signingRoot := utils.RandomSlice(32)

Expand All @@ -45,6 +47,7 @@ func TestPreCommitAnchor_Integration(t *testing.T) {
}

func TestPreCommit_CommitAnchor_Integration(t *testing.T) {
t.Parallel()
anchorIDPreImage := utils.RandomSlice(32)
h := sha256.New()
_, err := h.Write(anchorIDPreImage)
Expand Down Expand Up @@ -80,12 +83,13 @@ func TestPreCommit_CommitAnchor_Integration(t *testing.T) {

docRootTyped, _ := anchors.ToDocumentRoot(documentRoot)
commitAnchor(t, anchorIDPreImage, documentRoot, [][anchors.DocumentProofLength]byte{proofB1, proofB2})
gotDocRoot, err := anchorRepo.GetDocumentRootOf(anchorIDTyped)
gotDocRoot, _, err := anchorRepo.GetAnchorData(anchorIDTyped)
assert.Nil(t, err)
assert.Equal(t, docRootTyped, gotDocRoot)
}

func TestCommitAnchor_Integration(t *testing.T) {
t.Parallel()
anchorIDPreImage := utils.RandomSlice(32)
h := sha256.New()
_, err := h.Write(anchorIDPreImage)
Expand All @@ -98,9 +102,10 @@ func TestCommitAnchor_Integration(t *testing.T) {
assert.NoError(t, err)
docRootTyped, _ := anchors.ToDocumentRoot(documentRoot)
commitAnchor(t, anchorIDPreImage, documentRoot, [][anchors.DocumentProofLength]byte{utils.RandomByte32()})
gotDocRoot, err := anchorRepo.GetDocumentRootOf(anchorIDTyped)
gotDocRoot, hval, err := anchorRepo.GetAnchorData(anchorIDTyped)
assert.Nil(t, err)
assert.Equal(t, docRootTyped, gotDocRoot)
assert.True(t, time.Now().After(hval))
}

func commitAnchor(t *testing.T, anchorID, documentRoot []byte, documentProofs [][32]byte) {
Expand Down Expand Up @@ -133,6 +138,7 @@ func preCommitAnchor(t *testing.T, anchorID, documentRoot []byte) {
}

func TestCommitAnchor_Integration_Concurrent(t *testing.T) {
t.Parallel()
var commitDataList [5]*anchors.CommitData
var doneList [5]chan bool

Expand Down Expand Up @@ -165,7 +171,7 @@ func TestCommitAnchor_Integration_Concurrent(t *testing.T) {
assert.True(t, isDone)
anchorID := commitDataList[ix].AnchorID
docRoot := commitDataList[ix].DocumentRoot
gotDocRoot, err := anchorRepo.GetDocumentRootOf(anchorID)
gotDocRoot, _, err := anchorRepo.GetAnchorData(anchorID)
assert.Nil(t, err)
assert.Equal(t, docRoot, gotDocRoot)
}
Expand Down
9 changes: 6 additions & 3 deletions anchors/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package anchors
import (
"context"
"math/big"
"time"

"github.com/centrifuge/go-centrifuge/contextutil"
"github.com/centrifuge/go-centrifuge/ethereum"
Expand All @@ -20,6 +21,7 @@ type anchorRepositoryContract interface {
GetAnchorById(opts *bind.CallOpts, id *big.Int) (struct {
AnchorId *big.Int
DocumentRoot [32]byte
BlockNumber uint32
}, error)
HasValidPreCommit(opts *bind.CallOpts, anchorId *big.Int) (bool, error)
}
Expand Down Expand Up @@ -47,12 +49,13 @@ func (s *service) HasValidPreCommit(anchorID AnchorID) bool {
return r
}

// GetDocumentRootOf takes an anchorID and returns the corresponding documentRoot from the chain.
func (s *service) GetDocumentRootOf(anchorID AnchorID) (docRoot DocumentRoot, err error) {
// GetAnchorData takes an anchorID and returns the corresponding documentRoot from the chain.
func (s *service) GetAnchorData(anchorID AnchorID) (docRoot DocumentRoot, anchoredTime time.Time, err error) {
// Ignoring cancelFunc as code will block until response or timeout is triggered
opts, _ := s.client.GetGethCallOpts(false)
r, err := s.anchorRepositoryContract.GetAnchorById(opts, anchorID.BigInt())
return r.DocumentRoot, err
blk, err := s.client.GetEthClient().BlockByNumber(context.Background(), big.NewInt(int64(r.BlockNumber)))
return r.DocumentRoot, time.Unix(blk.Time().Int64(), 0), err
}

// PreCommitAnchor will call the transaction PreCommit on the smart contract
Expand Down
19 changes: 2 additions & 17 deletions anchors/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/centrifuge/go-centrifuge/crypto/secp256k1"
"github.com/centrifuge/go-centrifuge/identity"
"github.com/centrifuge/go-centrifuge/testingutils/commons"
"github.com/centrifuge/go-centrifuge/utils"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand All @@ -24,11 +23,13 @@ type mockAnchorRepo struct {
func (m *mockAnchorRepo) GetAnchorById(opts *bind.CallOpts, anchorID *big.Int) (struct {
AnchorId *big.Int
DocumentRoot [32]byte
BlockNumber uint32
}, error) {
args := m.Called(opts, anchorID)
type Response struct {
AnchorId *big.Int
DocumentRoot [32]byte
BlockNumber uint32
}
r := Response{}
dr := args.Get(0).([32]byte)
Expand Down Expand Up @@ -75,19 +76,3 @@ func TestGenerateAnchor(t *testing.T) {
assert.Equal(t, commitData.DocumentProofs, documentProofs, "Anchor should have the document proofs")

}

func TestGetDocumentRootOf(t *testing.T) {
repo := &mockAnchorRepo{}
anchorID, err := ToAnchorID(utils.RandomSlice(32))
assert.Nil(t, err)

ethClient := &testingcommons.MockEthClient{}
ethClient.On("GetGethCallOpts").Return(nil)
ethRepo := newService(cfg, repo, nil, ethClient, nil)
docRoot := utils.RandomByte32()
repo.On("GetAnchorById", mock.Anything, mock.Anything).Return(docRoot, nil)
gotRoot, err := ethRepo.GetDocumentRootOf(anchorID)
repo.AssertExpectations(t)
assert.Nil(t, err)
assert.Equal(t, docRoot[:], gotRoot[:])
}
12 changes: 6 additions & 6 deletions build/configs/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ networks:
ethereumNetworkId: 4
# Latest deployed Smart Contracts for the given testnet
contractAddresses:
identityFactory: "0xffe0612006eedaeda188cd9df54574a68920a97d"
anchorRepository: "0xd3be7846016367a08ad083b06df98ad78212d0a5"
paymentObligation: "0x2d5b6470af1ac962c55b6bee92f3c38c609f371e"
identityFactory: "0xb20f5ed00794c0cccc508b1d9fa882b631a3ff61"
anchorRepository: "0x2200d8c912551ccdcf960d302f318d3ece6d3959"
paymentObligation: "0x01ac3191b762e5072cc25ef5caede15a17840a89"

# Kovan test network
bernalheights:
Expand All @@ -49,9 +49,9 @@ networks:
ethereumNetworkId: 42
# Latest deployed Smart Contracts for the given testnet
contractAddresses:
identityFactory: "0x01adb663afd3a5d7655c89d2774cef51800f3bb6"
anchorRepository: "0x16f45eac73752eab73072fddbacbd0a58adc3a40"
paymentObligation: "0xeb1c6a36c4b1234aaae7ece88fb4f48d23d63146"
identityFactory: "0x4c840990c5e96f4c4458486d44c68ed7e95e0d52"
anchorRepository: "0x625b95d4705d75c485d1773c7201a7343643e11f"
paymentObligation: "0x8fb2efb77b2d8d09a793bd313ebc830a7e7090b7"

# Ropsten test network
dogpatch:
Expand Down
5 changes: 4 additions & 1 deletion build/scripts/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ set -x

CENT_MODE=${CENT_MODE:-run}

/root/centrifuge ${CENT_MODE} --config /root/.centrifuge/config/config.yaml $@
ETHKEY=`cat /root/.centrifuge/secrets/eth.key`
ETHPWD=`cat /root/.centrifuge/secrets/eth.pwd`

CENT_ETHEREUM_ACCOUNTS_MAIN_KEY=$ETHKEY CENT_ETHEREUM_ACCOUNTS_MAIN_PASSWORD=$ETHPWD /root/centrifuge ${CENT_MODE} --config /root/.centrifuge/config/config.yaml $@
2 changes: 2 additions & 0 deletions build/scripts/migrate.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -e

# Allow passing parent directory as a parameter
PARENT_DIR=$1
if [ -z ${PARENT_DIR} ];
Expand Down
20 changes: 15 additions & 5 deletions build/scripts/test_wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,24 @@ status=$?
############################################################

################# Run Tests ################################
if [ $status -eq 0 ]; then
args=( "$@" )
if [[ $# == 0 ]]; then
args=( unit cmd testworld integration )
fi

if [[ ${status} -eq 0 ]]; then
statusAux=0
for path in ${local_dir}/tests/*; do
[ -x "${path}" ] || continue # if not an executable, skip
[[ -x "${path}" ]] || continue # if not an executable, skip

echo "Executing test suite [${path}]"
./$path
statusAux="$(( $statusAux | $? ))"
for arg in "${args[@]}"; do
if [[ ${path} == *$arg* ]]; then
echo "Executing test suite [${path}]"
./$path
statusAux="$(( $statusAux | $? ))"
continue
fi
done
done
# Store status of tests
status=$statusAux
Expand Down
Loading

0 comments on commit a742b00

Please sign in to comment.