Compare commits

...
Author SHA1 Message Date
0xmuralik db2c3afef1 rename func 2023-03-10 16:50:47 +05:30
0xmuralik 8932d69f36 fix unit test CID 2023-03-09 00:47:04 +05:30
0xmuralik 1d73452ff6 replace fn 2023-03-07 14:51:54 +05:30
Michael c227a38e9a tests must be run against different chain configurations (#91)
* tests must be run against different chain configurations

* compose args order matters

* x bit not set on auction tests shell script

* always run docker compose down... possibly to avoid insufficient funds error after a failed run

* add arg to docker compose down for auction and nameservice-expiry

* switch to main branch
2023-02-10 14:44:27 -05:00
10 changed files with 122 additions and 37 deletions
+25 -2
View File
@@ -102,8 +102,31 @@ jobs:
run: docker compose up -d run: docker compose up -d
- name: run-tests.sh - name: run-tests.sh
working-directory: tests/sdk_tests working-directory: tests/sdk_tests
run: ./run-all-tests.sh run: ./run-tests.sh
- name: reset containers for auction tests
working-directory: tests/sdk_tests
if: always()
run: docker compose down
- name: start auction containers
working-directory: tests/sdk_tests
run: docker compose -f docker-compose-auctions.yml up -d
- name: run-acution-tests.sh
working-directory: tests/sdk_tests
run: ./run-auction-tests.sh
- name: reset containers for nameservice tests
working-directory: tests/sdk_tests
if: always()
run: docker compose -f docker-compose-auctions.yml down
- name: start auction containers
working-directory: tests/sdk_tests
run: docker compose -f docker-compose-nameservice.yml up -d
- name: run-nameservice-expiry-tests.sh
working-directory: tests/sdk_tests
run: ./run-nameservice-expiry-tests.sh
- name: reset containers for nameservice tests
working-directory: tests/sdk_tests
if: always()
run: docker compose -f docker-compose-nameservice.yml down
# integration_tests: # integration_tests:
# runs-on: ubuntu-latest # runs-on: ubuntu-latest
-1
View File
@@ -47,7 +47,6 @@ WORKDIR /app
RUN \ RUN \
git clone https://github.com/cerc-io/laconic-sdk.git \ git clone https://github.com/cerc-io/laconic-sdk.git \
&& cd laconic-sdk \ && cd laconic-sdk \
&& git checkout auction_nameservice_tests \
&& yarn install && yarn install
WORKDIR /app/laconic-sdk WORKDIR /app/laconic-sdk
@@ -0,0 +1,31 @@
services:
laconicd:
restart: unless-stopped
image: cerc-io/laconicd:local-test
environment:
- TEST_AUCTION_ENABLED=true
command: ["sh", "/docker-entrypoint-scripts.d/create-fixturenet.sh"]
volumes:
- ../../init.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh
healthcheck:
test: ["CMD", "curl", "-v", "http://127.0.0.1:6060"]
interval: 1s
timeout: 5s
retries: 30
ports:
- "6060"
- "26657"
- "26656"
- "9473"
- "8545"
- "8546"
- "9090"
- "9091"
- "1317"
sdk-test-runner:
image: cerc-io/laconic-sdk-tester:local-test
depends_on:
laconicd:
condition: service_healthy
command: tail -F /dev/null
@@ -0,0 +1,31 @@
services:
laconicd:
restart: unless-stopped
image: cerc-io/laconicd:local-test
environment:
- TEST_REGISTRY_EXPIRY=true
command: ["sh", "/docker-entrypoint-scripts.d/create-fixturenet.sh"]
volumes:
- ../../init.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh
healthcheck:
test: ["CMD", "curl", "-v", "http://127.0.0.1:6060"]
interval: 1s
timeout: 5s
retries: 30
ports:
- "6060"
- "26657"
- "26656"
- "9473"
- "8545"
- "8546"
- "9090"
- "9091"
- "1317"
sdk-test-runner:
image: cerc-io/laconic-sdk-tester:local-test
depends_on:
laconicd:
condition: service_healthy
command: tail -F /dev/null
-3
View File
@@ -2,9 +2,6 @@ services:
laconicd: laconicd:
restart: unless-stopped restart: unless-stopped
image: cerc-io/laconicd:local-test image: cerc-io/laconicd:local-test
environment:
- TEST_AUCTION_ENABLED=true
- TEST_REGISTRY_EXPIRY=true
command: ["sh", "/docker-entrypoint-scripts.d/create-fixturenet.sh"] command: ["sh", "/docker-entrypoint-scripts.d/create-fixturenet.sh"]
volumes: volumes:
- ../../init.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh - ../../init.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
# Get the key from laconicd
laconicd_key=$( docker compose exec laconicd echo y | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe )
# Set parameters for the test suite
cosmos_chain_id=laconic_9000-1
laconicd_rest_endpoint=http://laconicd:1317
laconicd_gql_endpoint=http://laconicd:9473/api
# Run tests
docker network inspect sdk_tests_default
sleep 30s
docker logs sdk_tests-laconicd-1
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test:auctions"
@@ -11,8 +11,6 @@ laconicd_gql_endpoint=http://laconicd:9473/api
# Run tests # Run tests
docker network inspect sdk_tests_default docker network inspect sdk_tests_default
sleep 30s sleep 30s
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test"
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test:auctions"
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test:nameservice-expiry"
docker logs sdk_tests-laconicd-1 docker logs sdk_tests-laconicd-1
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test:nameservice-expiry"
+7 -15
View File
@@ -10,7 +10,6 @@ import (
canonicalJson "github.com/gibson042/canonicaljson-go" canonicalJson "github.com/gibson042/canonicaljson-go"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/ipld/go-ipld-prime/codec/dagcbor" "github.com/ipld/go-ipld-prime/codec/dagcbor"
"github.com/ipld/go-ipld-prime/codec/dagjson" "github.com/ipld/go-ipld-prime/codec/dagjson"
"github.com/ipld/go-ipld-prime/linking" "github.com/ipld/go-ipld-prime/linking"
@@ -18,7 +17,6 @@ import (
"github.com/ipld/go-ipld-prime/multicodec" "github.com/ipld/go-ipld-prime/multicodec"
basicnode "github.com/ipld/go-ipld-prime/node/basic" basicnode "github.com/ipld/go-ipld-prime/node/basic"
"github.com/ipld/go-ipld-prime/storage/memstore" "github.com/ipld/go-ipld-prime/storage/memstore"
mh "github.com/multiformats/go-multihash"
) )
var store = memstore.Store{} var store = memstore.Store{}
@@ -35,7 +33,7 @@ func GenerateHash(json map[string]interface{}) (string, []byte, error) {
return "", nil, err return "", nil, err
} }
cidString, err := CIDFromJSONBytesUsingIpldPrime(content) cidString, err := CIDFromJSONBytes(content)
if err != nil { if err != nil {
return "", nil, err return "", nil, err
} }
@@ -43,16 +41,6 @@ func GenerateHash(json map[string]interface{}) (string, []byte, error) {
return cidString, content, nil return cidString, content, nil
} }
// CIDFromJSONBytes returns CID (cbor) for json (as bytes).
func CIDFromJSONBytes(content []byte) (string, error) {
cid, err := cbor.FromJSON(bytes.NewReader(content), mh.SHA2_256, -1)
if err != nil {
return "", err
}
return cid.String(), nil
}
// GetAttributeAsString returns a map attribute as string, if possible. // GetAttributeAsString returns a map attribute as string, if possible.
func GetAttributeAsString(obj map[string]interface{}, attr string) (string, error) { func GetAttributeAsString(obj map[string]interface{}, attr string) (string, error) {
if value, ok := obj[attr]; ok { if value, ok := obj[attr]; ok {
@@ -66,10 +54,14 @@ func GetAttributeAsString(obj map[string]interface{}, attr string) (string, erro
return "", errors.New("attribute not found") return "", errors.New("attribute not found")
} }
// CIDFromJSONBytesUsingIpldPrime returns CID (dagcbor) for json (as bytes). // CIDFromJSONBytes returns CID (dagcbor) for json (as bytes).
// This is combination of samples for unmarshalling and linking // This is combination of samples for unmarshalling and linking
// see: https://pkg.go.dev/github.com/ipld/go-ipld-prime // see: https://pkg.go.dev/github.com/ipld/go-ipld-prime
func CIDFromJSONBytesUsingIpldPrime(content []byte) (string, error) { func CIDFromJSONBytes(content []byte) (string, error) {
if len(content) == 0 {
return "", nil
}
np := basicnode.Prototype.Any // Pick a stle for the in-memory data. np := basicnode.Prototype.Any // Pick a stle for the in-memory data.
nb := np.NewBuilder() // Create a builder. nb := np.NewBuilder() // Create a builder.
err := dagjson.Decode(nb, bytes.NewReader(content)) // Hand the builder to decoding -- decoding will fill it in! err := dagjson.Decode(nb, bytes.NewReader(content)) // Hand the builder to decoding -- decoding will fill it in!
+9 -11
View File
@@ -1,8 +1,9 @@
package utils package utils
import ( import (
"github.com/stretchr/testify/require"
"testing" "testing"
"github.com/stretchr/testify/require"
) )
func TestAndValidateCIDGeneration(t *testing.T) { func TestAndValidateCIDGeneration(t *testing.T) {
@@ -11,13 +12,12 @@ func TestAndValidateCIDGeneration(t *testing.T) {
content string content string
expected string expected string
}{ }{
// empty string and empty json blows up {
// { "empty string", "", "",
// "empty string", "", "bafyreiengp2sbi6ez34a2jctv34bwyjl7yoliteleaswgcwtqzrhmpyt2m", },
// }, {
// { "empty json", "{}", "bafyreigbtj4x7ip5legnfznufuopl4sg4knzc2cof6duas4b3q2fy6swua",
// "empty json", "{}", "bafyreihpfkdvib5muloxlj5b3tgdwibjdcu3zdsuhyft33z7gtgnlzlkpm", },
// },
{ {
"test record", "{\"build_artifact_cid\":\"QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9\",\"repo_registration_record_cid\":\"QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D\",\"tls_cert_cid\":\"QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\",\"type\":\"WebsiteRegistrationRecord\",\"url\":\"https://cerc.io\",\"version\":\"0.0.1\"}", "test record", "{\"build_artifact_cid\":\"QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9\",\"repo_registration_record_cid\":\"QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D\",\"tls_cert_cid\":\"QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\",\"type\":\"WebsiteRegistrationRecord\",\"url\":\"https://cerc.io\",\"version\":\"0.0.1\"}",
@@ -26,10 +26,8 @@ func TestAndValidateCIDGeneration(t *testing.T) {
} }
for _, tc := range testCases { for _, tc := range testCases {
deprecatedAndCorrect, _ := CIDFromJSONBytes([]byte(tc.content)) newImpl, err := CIDFromJSONBytes([]byte(tc.content))
newImpl, err := CIDFromJSONBytesUsingIpldPrime([]byte(tc.content))
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, deprecatedAndCorrect, newImpl, tc.name)
require.Equal(t, tc.expected, newImpl) require.Equal(t, tc.expected, newImpl)
} }
} }
+1 -1
View File
@@ -70,7 +70,7 @@ func UnMarshalMapFromJSONBytes(bytes []byte) map[string]interface{} {
// GetCid gets the content ID. // GetCid gets the content ID.
func GetCid(content []byte) (string, error) { func GetCid(content []byte) (string, error) {
return wnsUtils.CIDFromJSONBytesUsingIpldPrime(content) return wnsUtils.CIDFromJSONBytes(content)
} }
// BytesToBase64 encodes a byte array as a base64 string. // BytesToBase64 encodes a byte array as a base64 string.