From 9c1b8e59899db33d6e40f80d135ab341d8e3b2af Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Mon, 11 Oct 2021 12:52:04 -0400 Subject: [PATCH 1/3] Run E2E tests with matrix including fabric Signed-off-by: Nicko Guyer --- .github/workflows/go.yml | 11 ++ test/e2e/e2e_test.go | 263 ------------------------------ test/e2e/ethereum_test.go | 28 ++++ test/e2e/fabric_test.go | 27 +++ test/e2e/onchain_offchain_test.go | 251 ++++++++++++++++++++++++++++ test/e2e/run.sh | 17 +- test/e2e/tokens_test.go | 69 ++++++++ 7 files changed, 401 insertions(+), 265 deletions(-) create mode 100644 test/e2e/ethereum_test.go create mode 100644 test/e2e/fabric_test.go create mode 100644 test/e2e/onchain_offchain_test.go create mode 100644 test/e2e/tokens_test.go diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0e11933747..92b26dcfa5 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -26,6 +26,14 @@ jobs: e2e-test: runs-on: ubuntu-latest + strategy: + matrix: + include: + - test-suite: TestEthereumE2ESuite + blockchain-provider: geth + - test-suite: TestFabricE2ESuite + blockchain-provider: fabric + fail-fast: false steps: - uses: actions/checkout@v2 @@ -35,6 +43,9 @@ jobs: go-version: 1.16 - name: Run E2E tests + env: + TEST_SUITE: ${{ matrix.test-suite }} + BLOCKCHAIN_PROVIDER: ${{ matrix.blockchain-provider }} run: ./test/e2e/run.sh - name: Archive container logs diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 1778afdd79..99cab7fc81 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -17,17 +17,14 @@ package e2e import ( - "bytes" "context" "crypto/sha256" "encoding/base64" "encoding/json" "fmt" - "image/png" "net/http" "net/url" "os" - "strings" "testing" "time" @@ -36,8 +33,6 @@ import ( "github.com/hyperledger/firefly/pkg/fftypes" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - image2ascii "github.com/qeesung/image2ascii/convert" ) type testState struct { @@ -243,261 +238,3 @@ func wsReader(t *testing.T, conn *websocket.Conn) (chan *fftypes.EventDelivery, }() return events, changeEvents } - -func TestE2EBroadcast(t *testing.T) { - - ts := beforeE2ETest(t) - defer ts.done() - - received1, changes1 := wsReader(t, ts.ws1) - received2, changes2 := wsReader(t, ts.ws2) - - var resp *resty.Response - value := fftypes.Byteable(`"Hello"`) - data := fftypes.DataRefOrValue{ - Value: value, - } - - resp, err := BroadcastMessage(ts.client1, &data) - require.NoError(t, err) - assert.Equal(t, 202, resp.StatusCode()) - - <-received1 - <-changes1 // also expect database change events - val1 := validateReceivedMessages(ts, ts.client1, fftypes.MessageTypeBroadcast, fftypes.TransactionTypeBatchPin, 1, 0) - assert.Equal(t, data.Value, val1) - - <-received2 - <-changes2 // also expect database change events - val2 := validateReceivedMessages(ts, ts.client2, fftypes.MessageTypeBroadcast, fftypes.TransactionTypeBatchPin, 1, 0) - assert.Equal(t, data.Value, val2) - -} - -func TestE2EPrivate(t *testing.T) { - - ts := beforeE2ETest(t) - defer ts.done() - - received1, _ := wsReader(t, ts.ws1) - received2, _ := wsReader(t, ts.ws2) - - var resp *resty.Response - value := fftypes.Byteable(`"Hello"`) - data := fftypes.DataRefOrValue{ - Value: value, - } - - resp, err := PrivateMessage(t, ts.client1, &data, []string{ - ts.org1.Name, - ts.org2.Name, - }, "", fftypes.TransactionTypeBatchPin) - require.NoError(t, err) - assert.Equal(t, 202, resp.StatusCode()) - - <-received1 - val1 := validateReceivedMessages(ts, ts.client1, fftypes.MessageTypePrivate, fftypes.TransactionTypeBatchPin, 1, 0) - assert.Equal(t, data.Value, val1) - - <-received2 - val2 := validateReceivedMessages(ts, ts.client2, fftypes.MessageTypePrivate, fftypes.TransactionTypeBatchPin, 1, 0) - assert.Equal(t, data.Value, val2) -} - -func TestE2EBroadcastBlob(t *testing.T) { - - ts := beforeE2ETest(t) - defer ts.done() - - received1, _ := wsReader(t, ts.ws1) - received2, _ := wsReader(t, ts.ws2) - - var resp *resty.Response - - resp, err := BroadcastBlobMessage(t, ts.client1) - require.NoError(t, err) - assert.Equal(t, 202, resp.StatusCode()) - - <-received1 - val1 := validateReceivedMessages(ts, ts.client1, fftypes.MessageTypeBroadcast, fftypes.TransactionTypeBatchPin, 1, 0) - assert.Regexp(t, "myfile.txt", string(val1)) - - <-received2 - val2 := validateReceivedMessages(ts, ts.client2, fftypes.MessageTypeBroadcast, fftypes.TransactionTypeBatchPin, 1, 0) - assert.Regexp(t, "myfile.txt", string(val2)) - -} - -func TestE2EPrivateBlobDatatypeTagged(t *testing.T) { - - ts := beforeE2ETest(t) - defer ts.done() - - received1, _ := wsReader(t, ts.ws1) - received2, _ := wsReader(t, ts.ws2) - - var resp *resty.Response - - resp, err := PrivateBlobMessageDatatypeTagged(t, ts.client1, []string{ - ts.org1.Name, - ts.org2.Name, - }) - require.NoError(t, err) - assert.Equal(t, 202, resp.StatusCode()) - - <-received1 - _ = validateReceivedMessages(ts, ts.client1, fftypes.MessageTypePrivate, fftypes.TransactionTypeBatchPin, 1, 0) - - <-received2 - _ = validateReceivedMessages(ts, ts.client2, fftypes.MessageTypePrivate, fftypes.TransactionTypeBatchPin, 1, 0) -} - -func TestE2ETokenPool(t *testing.T) { - - ts := beforeE2ETest(t) - defer ts.done() - - received1, changes1 := wsReader(t, ts.ws1) - received2, changes2 := wsReader(t, ts.ws2) - - pools := GetTokenPools(t, ts.client1, time.Unix(0, 0)) - poolName := fmt.Sprintf("pool%d", len(pools)) - t.Logf("Pool name: %s", poolName) - - pool := &fftypes.TokenPool{ - Name: poolName, - Type: fftypes.TokenTypeFungible, - } - CreateTokenPool(t, ts.client1, pool) - - <-received1 - <-changes1 // also expect database change events - - pools1 := GetTokenPools(t, ts.client1, ts.startTime) - assert.Equal(t, 1, len(pools1)) - assert.Equal(t, "default", pools1[0].Namespace) - assert.Equal(t, poolName, pools1[0].Name) - assert.Equal(t, fftypes.TokenTypeFungible, pools1[0].Type) - - <-received2 - <-changes2 // also expect database change events - - pools2 := GetTokenPools(t, ts.client1, ts.startTime) - assert.Equal(t, 1, len(pools2)) - assert.Equal(t, "default", pools2[0].Namespace) - assert.Equal(t, poolName, pools2[0].Name) - assert.Equal(t, fftypes.TokenTypeFungible, pools2[0].Type) -} - -func TestE2EWebhookExchange(t *testing.T) { - - ts := beforeE2ETest(t) - defer ts.done() - - received1, _ := wsReader(t, ts.ws1) - received2, _ := wsReader(t, ts.ws2) - - subJSON := `{ - "transport": "webhooks", - "namespace": "default", - "name": "myhook", - "options": { - "withData": true, - "url": "https://raw.githubusercontent.com/hyperledger/firefly/main/test/data/config/firefly.core.yaml", - "reply": true, - "replytag": "myreply", - "method": "GET" - }, - "filter": { - "tag": "myrequest" - } - }` - CleanupExistingSubscription(t, ts.client2, "default", "myhook") - sub := CreateSubscription(t, ts.client2, subJSON, 201) - assert.NotNil(t, sub.ID) - - data := fftypes.DataRefOrValue{ - Value: fftypes.Byteable(`{}`), - } - - var resp *resty.Response - resp, err := PrivateMessage(t, ts.client1, &data, []string{ - ts.org1.Name, - ts.org2.Name, - }, "myrequest", fftypes.TransactionTypeBatchPin) - require.NoError(t, err) - assert.Equal(t, 202, resp.StatusCode()) - - <-received1 // request - <-received2 // request - - <-received1 // reply - val1 := validateReceivedMessages(ts, ts.client1, fftypes.MessageTypePrivate, fftypes.TransactionTypeBatchPin, 2, 0) - assert.Equal(t, float64(200), val1.JSONObject()["status"]) - decoded1, err := base64.StdEncoding.DecodeString(val1.JSONObject().GetString("body")) - assert.NoError(t, err) - assert.Regexp(t, "Example YAML", string(decoded1)) - - <-received2 // reply - val2 := validateReceivedMessages(ts, ts.client1, fftypes.MessageTypePrivate, fftypes.TransactionTypeBatchPin, 2, 0) - assert.Equal(t, float64(200), val2.JSONObject()["status"]) - decoded2, err := base64.StdEncoding.DecodeString(val2.JSONObject().GetString("body")) - assert.NoError(t, err) - assert.Regexp(t, "Example YAML", string(decoded2)) -} - -func TestE2EWebhookRequestReplyNoTx(t *testing.T) { - - ts := beforeE2ETest(t) - defer ts.done() - - subJSON := `{ - "transport": "webhooks", - "namespace": "default", - "name": "myhook", - "options": { - "withData": true, - "url": "https://github.com/hyperledger/firefly/raw/main/resources/ff-logo-32.png", - "reply": true, - "replytag": "myreply", - "replytx": "none", - "method": "GET" - }, - "filter": { - "tag": "myrequest" - } - }` - CleanupExistingSubscription(t, ts.client2, "default", "myhook") - sub := CreateSubscription(t, ts.client2, subJSON, 201) - assert.NotNil(t, sub.ID) - - data := fftypes.DataRefOrValue{ - Value: fftypes.Byteable(`{}`), - } - - reply := RequestReply(t, ts.client1, &data, []string{ - ts.org1.Name, - ts.org2.Name, - }, "myrequest", fftypes.TransactionTypeNone) - assert.NotNil(t, reply) - - bodyData := reply.InlineData[0].Value.JSONObject().GetString("body") - b, err := base64.StdEncoding.DecodeString(bodyData) - assert.NoError(t, err) - ffImg, err := png.Decode(bytes.NewReader(b)) - assert.NoError(t, err) - - // Verify we got the right data back by parsing it - convertOptions := image2ascii.DefaultOptions - convertOptions.FixedWidth = 100 - convertOptions.FixedHeight = 60 - convertOptions.Colored = false - converter := image2ascii.NewImageConverter() - str := converter.Image2ASCIIString(ffImg, &convertOptions) - for _, s := range strings.Split(str, "\n") { - if len(strings.TrimSpace(s)) > 0 { - fmt.Println(s) - } - } - -} diff --git a/test/e2e/ethereum_test.go b/test/e2e/ethereum_test.go new file mode 100644 index 0000000000..66e037b267 --- /dev/null +++ b/test/e2e/ethereum_test.go @@ -0,0 +1,28 @@ +// Copyright © 2021 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package e2e + +import ( + "testing" + + "github.com/stretchr/testify/suite" +) + +func TestEthereumE2ESuite(t *testing.T) { + suite.Run(t, new(OnChainOffChainTestSuite)) + suite.Run(t, new(TokensTestSuite)) +} diff --git a/test/e2e/fabric_test.go b/test/e2e/fabric_test.go new file mode 100644 index 0000000000..4082650027 --- /dev/null +++ b/test/e2e/fabric_test.go @@ -0,0 +1,27 @@ +// Copyright © 2021 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package e2e + +import ( + "testing" + + "github.com/stretchr/testify/suite" +) + +func TestFabricE2ESuite(t *testing.T) { + suite.Run(t, new(OnChainOffChainTestSuite)) +} diff --git a/test/e2e/onchain_offchain_test.go b/test/e2e/onchain_offchain_test.go new file mode 100644 index 0000000000..bf7fe05e6b --- /dev/null +++ b/test/e2e/onchain_offchain_test.go @@ -0,0 +1,251 @@ +// Copyright © 2021 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package e2e + +import ( + "bytes" + "encoding/base64" + "fmt" + "image/png" + "strings" + + "github.com/go-resty/resty/v2" + "github.com/hyperledger/firefly/pkg/fftypes" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + + image2ascii "github.com/qeesung/image2ascii/convert" +) + +type OnChainOffChainTestSuite struct { + suite.Suite + testState *testState +} + +func (suite *OnChainOffChainTestSuite) BeforeTest(suiteName, testName string) { + suite.testState = beforeE2ETest(suite.T()) +} + +func (suite *OnChainOffChainTestSuite) TestE2EBroadcast() { + defer suite.testState.done() + + received1, changes1 := wsReader(suite.T(), suite.testState.ws1) + received2, changes2 := wsReader(suite.T(), suite.testState.ws2) + + var resp *resty.Response + value := fftypes.Byteable(`"Hello"`) + data := fftypes.DataRefOrValue{ + Value: value, + } + + resp, err := BroadcastMessage(suite.testState.client1, &data) + require.NoError(suite.T(), err) + assert.Equal(suite.T(), 202, resp.StatusCode()) + + <-received1 + <-changes1 // also expect database change events + val1 := validateReceivedMessages(suite.testState, suite.testState.client1, fftypes.MessageTypeBroadcast, fftypes.TransactionTypeBatchPin, 1, 0) + assert.Equal(suite.T(), data.Value, val1) + + <-received2 + <-changes2 // also expect database change events + val2 := validateReceivedMessages(suite.testState, suite.testState.client2, fftypes.MessageTypeBroadcast, fftypes.TransactionTypeBatchPin, 1, 0) + assert.Equal(suite.T(), data.Value, val2) + +} + +func (suite *OnChainOffChainTestSuite) TestE2EPrivate() { + defer suite.testState.done() + + received1, _ := wsReader(suite.T(), suite.testState.ws1) + received2, _ := wsReader(suite.T(), suite.testState.ws2) + + var resp *resty.Response + value := fftypes.Byteable(`"Hello"`) + data := fftypes.DataRefOrValue{ + Value: value, + } + + resp, err := PrivateMessage(suite.T(), suite.testState.client1, &data, []string{ + suite.testState.org1.Name, + suite.testState.org2.Name, + }, "", fftypes.TransactionTypeBatchPin) + require.NoError(suite.T(), err) + assert.Equal(suite.T(), 202, resp.StatusCode()) + + <-received1 + val1 := validateReceivedMessages(suite.testState, suite.testState.client1, fftypes.MessageTypePrivate, fftypes.TransactionTypeBatchPin, 1, 0) + assert.Equal(suite.T(), data.Value, val1) + + <-received2 + val2 := validateReceivedMessages(suite.testState, suite.testState.client2, fftypes.MessageTypePrivate, fftypes.TransactionTypeBatchPin, 1, 0) + assert.Equal(suite.T(), data.Value, val2) +} + +func (suite *OnChainOffChainTestSuite) TestE2EBroadcastBlob() { + defer suite.testState.done() + + received1, _ := wsReader(suite.T(), suite.testState.ws1) + received2, _ := wsReader(suite.T(), suite.testState.ws2) + + var resp *resty.Response + + resp, err := BroadcastBlobMessage(suite.T(), suite.testState.client1) + require.NoError(suite.T(), err) + assert.Equal(suite.T(), 202, resp.StatusCode()) + + <-received1 + val1 := validateReceivedMessages(suite.testState, suite.testState.client1, fftypes.MessageTypeBroadcast, fftypes.TransactionTypeBatchPin, 1, 0) + assert.Regexp(suite.T(), "myfile.txt", string(val1)) + + <-received2 + val2 := validateReceivedMessages(suite.testState, suite.testState.client2, fftypes.MessageTypeBroadcast, fftypes.TransactionTypeBatchPin, 1, 0) + assert.Regexp(suite.T(), "myfile.txt", string(val2)) + +} + +func (suite *OnChainOffChainTestSuite) TestE2EPrivateBlobDatatypeTagged() { + defer suite.testState.done() + + received1, _ := wsReader(suite.T(), suite.testState.ws1) + received2, _ := wsReader(suite.T(), suite.testState.ws2) + + var resp *resty.Response + + resp, err := PrivateBlobMessageDatatypeTagged(suite.T(), suite.testState.client1, []string{ + suite.testState.org1.Name, + suite.testState.org2.Name, + }) + require.NoError(suite.T(), err) + assert.Equal(suite.T(), 202, resp.StatusCode()) + + <-received1 + _ = validateReceivedMessages(suite.testState, suite.testState.client1, fftypes.MessageTypePrivate, fftypes.TransactionTypeBatchPin, 1, 0) + + <-received2 + _ = validateReceivedMessages(suite.testState, suite.testState.client2, fftypes.MessageTypePrivate, fftypes.TransactionTypeBatchPin, 1, 0) +} + +func (suite *OnChainOffChainTestSuite) TestE2EWebhookExchange() { + defer suite.testState.done() + + received1, _ := wsReader(suite.T(), suite.testState.ws1) + received2, _ := wsReader(suite.T(), suite.testState.ws2) + + subJSON := `{ + "transport": "webhooks", + "namespace": "default", + "name": "myhook", + "options": { + "withData": true, + "url": "https://raw.githubusercontent.com/hyperledger/firefly/main/test/data/config/firefly.core.yaml", + "reply": true, + "replytag": "myreply", + "method": "GET" + }, + "filter": { + "tag": "myrequest" + } + }` + CleanupExistingSubscription(suite.T(), suite.testState.client2, "default", "myhook") + sub := CreateSubscription(suite.T(), suite.testState.client2, subJSON, 201) + assert.NotNil(suite.T(), sub.ID) + + data := fftypes.DataRefOrValue{ + Value: fftypes.Byteable(`{}`), + } + + var resp *resty.Response + resp, err := PrivateMessage(suite.T(), suite.testState.client1, &data, []string{ + suite.testState.org1.Name, + suite.testState.org2.Name, + }, "myrequest", fftypes.TransactionTypeBatchPin) + require.NoError(suite.T(), err) + assert.Equal(suite.T(), 202, resp.StatusCode()) + + <-received1 // request + <-received2 // request + + <-received1 // reply + val1 := validateReceivedMessages(suite.testState, suite.testState.client1, fftypes.MessageTypePrivate, fftypes.TransactionTypeBatchPin, 2, 0) + assert.Equal(suite.T(), float64(200), val1.JSONObject()["status"]) + decoded1, err := base64.StdEncoding.DecodeString(val1.JSONObject().GetString("body")) + assert.NoError(suite.T(), err) + assert.Regexp(suite.T(), "Example YAML", string(decoded1)) + + <-received2 // reply + val2 := validateReceivedMessages(suite.testState, suite.testState.client1, fftypes.MessageTypePrivate, fftypes.TransactionTypeBatchPin, 2, 0) + assert.Equal(suite.T(), float64(200), val2.JSONObject()["status"]) + decoded2, err := base64.StdEncoding.DecodeString(val2.JSONObject().GetString("body")) + assert.NoError(suite.T(), err) + assert.Regexp(suite.T(), "Example YAML", string(decoded2)) +} + +func (suite *OnChainOffChainTestSuite) TestE2EWebhookRequestReplyNoTx() { + defer suite.testState.done() + + subJSON := `{ + "transport": "webhooks", + "namespace": "default", + "name": "myhook", + "options": { + "withData": true, + "url": "https://github.com/hyperledger/firefly/raw/main/resources/ff-logo-32.png", + "reply": true, + "replytag": "myreply", + "replytx": "none", + "method": "GET" + }, + "filter": { + "tag": "myrequest" + } + }` + CleanupExistingSubscription(suite.T(), suite.testState.client2, "default", "myhook") + sub := CreateSubscription(suite.T(), suite.testState.client2, subJSON, 201) + assert.NotNil(suite.T(), sub.ID) + + data := fftypes.DataRefOrValue{ + Value: fftypes.Byteable(`{}`), + } + + reply := RequestReply(suite.T(), suite.testState.client1, &data, []string{ + suite.testState.org1.Name, + suite.testState.org2.Name, + }, "myrequest", fftypes.TransactionTypeNone) + assert.NotNil(suite.T(), reply) + + bodyData := reply.InlineData[0].Value.JSONObject().GetString("body") + b, err := base64.StdEncoding.DecodeString(bodyData) + assert.NoError(suite.T(), err) + ffImg, err := png.Decode(bytes.NewReader(b)) + assert.NoError(suite.T(), err) + + // Verify we got the right data back by parsing it + convertOptions := image2ascii.DefaultOptions + convertOptions.FixedWidth = 100 + convertOptions.FixedHeight = 60 + convertOptions.Colored = false + converter := image2ascii.NewImageConverter() + str := converter.Image2ASCIIString(ffImg, &convertOptions) + for _, s := range strings.Split(str, "\n") { + if len(strings.TrimSpace(s)) > 0 { + fmt.Println(s) + } + } + +} diff --git a/test/e2e/run.sh b/test/e2e/run.sh index f8fed4f7c0..24e9726df9 100755 --- a/test/e2e/run.sh +++ b/test/e2e/run.sh @@ -41,6 +41,19 @@ if [ -z "${STACK_FILE}" ]; then STACK_FILE=$STACK_DIR/$STACK_NAME/stack.json fi + +if [ -z "${BLOCKCHAIN_PROVIDER}" ]; then + BLOCKCHAIN_PROVIDER=geth +fi + +if [ -z "${TOKENS_PROVIDER}" ]; then + TOKENS_PROVIDER=erc1155 +fi + +if [ -z "${TEST_SUITE}" ]; then + TEST_SUITE=TestEthereumE2ESuite +fi + cd $CWD if [ "$CREATE_STACK" == "true" ]; then @@ -59,7 +72,7 @@ if [ "$DOWNLOAD_CLI" == "true" ]; then fi if [ "$CREATE_STACK" == "true" ]; then - $CLI init --database $DATABASE_TYPE $STACK_NAME 2 + $CLI init --database $DATABASE_TYPE $STACK_NAME 2 --blockchain-provider $BLOCKCHAIN_PROVIDER --tokens-provider $TOKENS_PROVIDER checkOk $? $CLI start -nb $STACK_NAME @@ -71,5 +84,5 @@ checkOk $? export STACK_FILE -go clean -testcache && go test -v . +go clean -testcache && go test -v . -run $TEST_SUITE checkOk $? diff --git a/test/e2e/tokens_test.go b/test/e2e/tokens_test.go new file mode 100644 index 0000000000..4f1182d122 --- /dev/null +++ b/test/e2e/tokens_test.go @@ -0,0 +1,69 @@ +// Copyright © 2021 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package e2e + +import ( + "fmt" + "time" + + "github.com/hyperledger/firefly/pkg/fftypes" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" +) + +type TokensTestSuite struct { + suite.Suite + testState *testState +} + +func (suite *TokensTestSuite) BeforeTest(suiteName, testName string) { + suite.testState = beforeE2ETest(suite.T()) +} +func (suite *TokensTestSuite) TestE2ETokenPool() { + defer suite.testState.done() + + received1, changes1 := wsReader(suite.T(), suite.testState.ws1) + received2, changes2 := wsReader(suite.T(), suite.testState.ws2) + + pools := GetTokenPools(suite.T(), suite.testState.client1, time.Unix(0, 0)) + poolName := fmt.Sprintf("pool%d", len(pools)) + suite.T().Logf("Pool name: %s", poolName) + + pool := &fftypes.TokenPool{ + Name: poolName, + Type: fftypes.TokenTypeFungible, + } + CreateTokenPool(suite.T(), suite.testState.client1, pool) + + <-received1 + <-changes1 // also expect database change events + + pools1 := GetTokenPools(suite.T(), suite.testState.client1, suite.testState.startTime) + assert.Equal(suite.T(), 1, len(pools1)) + assert.Equal(suite.T(), "default", pools1[0].Namespace) + assert.Equal(suite.T(), poolName, pools1[0].Name) + assert.Equal(suite.T(), fftypes.TokenTypeFungible, pools1[0].Type) + + <-received2 + <-changes2 // also expect database change events + + pools2 := GetTokenPools(suite.T(), suite.testState.client1, suite.testState.startTime) + assert.Equal(suite.T(), 1, len(pools2)) + assert.Equal(suite.T(), "default", pools2[0].Namespace) + assert.Equal(suite.T(), poolName, pools2[0].Name) + assert.Equal(suite.T(), fftypes.TokenTypeFungible, pools2[0].Type) +} From 5201034f0e27ea84db8b488866fcc081217433ef Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Tue, 26 Oct 2021 13:04:38 -0400 Subject: [PATCH 2/3] Use more flexible matrix syntax Signed-off-by: Nicko Guyer --- .github/workflows/go.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 92b26dcfa5..f35ae07ff5 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -28,11 +28,14 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - include: - - test-suite: TestEthereumE2ESuite - blockchain-provider: geth - - test-suite: TestFabricE2ESuite - blockchain-provider: fabric + blockchain-provider: [geth, fabric] + database-type: [sqlite3] + test-suite: [TestEthereumE2ESuite, TestFabricE2ESuite] + exclude: + - blockchain-provider: geth + test-suite: TestFabricE2ESuite + - blockchain-provider: fabric + test-suite: TestEthereumE2ESuite fail-fast: false steps: - uses: actions/checkout@v2 @@ -46,6 +49,7 @@ jobs: env: TEST_SUITE: ${{ matrix.test-suite }} BLOCKCHAIN_PROVIDER: ${{ matrix.blockchain-provider }} + DATABASE_TYPE: ${{ matrix.database-type }} run: ./test/e2e/run.sh - name: Archive container logs From c1d9804a2458ca1dcb626002a879feb477d020bd Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Wed, 27 Oct 2021 08:46:20 -0400 Subject: [PATCH 3/3] Bump CLI version Signed-off-by: Nicko Guyer --- test/e2e/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/run.sh b/test/e2e/run.sh index 367f1f2086..f77ff457af 100755 --- a/test/e2e/run.sh +++ b/test/e2e/run.sh @@ -67,7 +67,7 @@ if [ "$BUILD_FIREFLY" == "true" ]; then fi if [ "$DOWNLOAD_CLI" == "true" ]; then - go install github.com/hyperledger/firefly-cli/ff@v0.0.35 + go install github.com/hyperledger/firefly-cli/ff@v0.0.36 checkOk $? fi