forked from cerc-io/laconicd-deprecated
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
748cc65b9f | ||
|
|
cc2c94cd1c | ||
|
|
43545537e1 | ||
|
|
6fa47fa27c | ||
|
|
8d866149bc | ||
|
|
7ee03b47d1 | ||
|
|
4f5562d26f | ||
|
|
facd64a14b |
@@ -36,7 +36,7 @@ jobs:
|
|||||||
- uses: codecov/codecov-action@v3
|
- uses: codecov/codecov-action@v3
|
||||||
with:
|
with:
|
||||||
file: ./coverage.txt
|
file: ./coverage.txt
|
||||||
fail_ci_if_error: true
|
fail_ci_if_error: false
|
||||||
if: env.GIT_DIFF
|
if: env.GIT_DIFF
|
||||||
|
|
||||||
test-importer:
|
test-importer:
|
||||||
@@ -91,6 +91,7 @@ jobs:
|
|||||||
path: "./laconic-sdk/"
|
path: "./laconic-sdk/"
|
||||||
repository: cerc-io/laconic-sdk
|
repository: cerc-io/laconic-sdk
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
ref: jest_timeout
|
||||||
- name: Environment
|
- name: Environment
|
||||||
run: ls -tlh && env
|
run: ls -tlh && env
|
||||||
- name: build containers scripts
|
- name: build containers scripts
|
||||||
@@ -101,7 +102,7 @@ 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-tests.sh
|
run: ./run-all-tests.sh
|
||||||
|
|
||||||
|
|
||||||
# integration_tests:
|
# integration_tests:
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ coverage.txt
|
|||||||
sim_log_file
|
sim_log_file
|
||||||
tests/**/tmp/*
|
tests/**/tmp/*
|
||||||
yarn.lock
|
yarn.lock
|
||||||
|
x/auction/client/testutil/bidder-bafyre*
|
||||||
|
|
||||||
# Vagrant
|
# Vagrant
|
||||||
.vagrant/
|
.vagrant/
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ RUN make build
|
|||||||
FROM alpine:3.17.0
|
FROM alpine:3.17.0
|
||||||
|
|
||||||
# Install ca-certificates
|
# Install ca-certificates
|
||||||
RUN apk add --update ca-certificates jq
|
RUN apk add --update ca-certificates jq curl
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
|
|
||||||
# Copy over binaries from the build-env
|
# Copy over binaries from the build-env
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ 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
|
||||||
|
|||||||
@@ -2,11 +2,14 @@ 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
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "wget", "-nv", "-t1", "--spider", "http://localhost:6060"]
|
test: ["CMD", "curl", "-v", "http://127.0.0.1:6060"]
|
||||||
interval: 1s
|
interval: 1s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 30
|
retries: 30
|
||||||
|
|||||||
Executable
+18
@@ -0,0 +1,18 @@
|
|||||||
|
#!/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 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
|
||||||
@@ -9,4 +9,10 @@ cosmos_chain_id=laconic_9000-1
|
|||||||
laconicd_rest_endpoint=http://laconicd:1317
|
laconicd_rest_endpoint=http://laconicd:1317
|
||||||
laconicd_gql_endpoint=http://laconicd:9473/api
|
laconicd_gql_endpoint=http://laconicd:9473/api
|
||||||
# Run tests
|
# Run tests
|
||||||
|
docker network inspect sdk_tests_default
|
||||||
|
sleep 30s
|
||||||
|
docker logs laconicd
|
||||||
|
docker compose exec laconicd sh -c "curl http://127.0.0.1:9473/api"
|
||||||
|
docker compose exec laconicd sh -c "curl http://localhost:9473/api"
|
||||||
|
|
||||||
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"
|
||||||
|
|||||||
+16
-15
@@ -8,17 +8,16 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/ipld/go-ipld-prime/codec/dagcbor"
|
|
||||||
"github.com/ipld/go-ipld-prime/fluent"
|
|
||||||
"github.com/ipld/go-ipld-prime/linking"
|
|
||||||
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
|
|
||||||
"github.com/ipld/go-ipld-prime/multicodec"
|
|
||||||
"github.com/ipld/go-ipld-prime/storage/memstore"
|
|
||||||
|
|
||||||
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"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
|
"github.com/ipld/go-ipld-prime/codec/dagcbor"
|
||||||
|
"github.com/ipld/go-ipld-prime/codec/dagjson"
|
||||||
|
"github.com/ipld/go-ipld-prime/linking"
|
||||||
|
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
|
||||||
|
"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"
|
||||||
mh "github.com/multiformats/go-multihash"
|
mh "github.com/multiformats/go-multihash"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -68,7 +67,17 @@ func GetAttributeAsString(obj map[string]interface{}, attr string) (string, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CIDFromJSONBytesUsingIpldPrime returns CID (dagcbor) for json (as bytes).
|
// CIDFromJSONBytesUsingIpldPrime returns CID (dagcbor) for json (as bytes).
|
||||||
|
// This is combination of samples for unmarshalling and linking
|
||||||
|
// see: https://pkg.go.dev/github.com/ipld/go-ipld-prime
|
||||||
func CIDFromJSONBytesUsingIpldPrime(content []byte) (string, error) {
|
func CIDFromJSONBytesUsingIpldPrime(content []byte) (string, error) {
|
||||||
|
np := basicnode.Prototype.Any // Pick a stle for the in-memory data.
|
||||||
|
nb := np.NewBuilder() // Create a builder.
|
||||||
|
err := dagjson.Decode(nb, bytes.NewReader(content)) // Hand the builder to decoding -- decoding will fill it in!
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
n := nb.Build() // Call 'Build' to get the resulting Node. (It's immutable!)
|
||||||
|
|
||||||
lsys := cidlink.DefaultLinkSystem()
|
lsys := cidlink.DefaultLinkSystem()
|
||||||
|
|
||||||
// We want to store the serialized data somewhere.
|
// We want to store the serialized data somewhere.
|
||||||
@@ -87,14 +96,6 @@ func CIDFromJSONBytesUsingIpldPrime(content []byte) (string, error) {
|
|||||||
MhLength: 32, // sha2-256 hash has a 32-byte sum.
|
MhLength: 32, // sha2-256 hash has a 32-byte sum.
|
||||||
}}
|
}}
|
||||||
|
|
||||||
// And we need some data to link to! Here's a quick piece of example data:
|
|
||||||
n, err := fluent.Build(basicnode.Prototype.Any, func(na fluent.NodeAssembler) {
|
|
||||||
na.AssignBytes(content)
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now: time to apply the LinkSystem, and do the actual store operation!
|
// Now: time to apply the LinkSystem, and do the actual store operation!
|
||||||
lnk, err := lsys.Store(
|
lnk, err := lsys.Store(
|
||||||
linking.LinkContext{}, // The zero value is fine. Configure it it you want cancellability or other features.
|
linking.LinkContext{}, // The zero value is fine. Configure it it you want cancellability or other features.
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAndValidateCIDGeneration(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
content string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
// empty string and empty json blows up
|
||||||
|
// {
|
||||||
|
// "empty string", "", "bafyreiengp2sbi6ez34a2jctv34bwyjl7yoliteleaswgcwtqzrhmpyt2m",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "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\"}",
|
||||||
|
"bafyreiek4hnoqmits66bjyxswapplweuoqe4en2ux6u772o4y3askpd3ny",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
deprecatedAndCorrect, _ := CIDFromJSONBytes([]byte(tc.content))
|
||||||
|
newImpl, err := CIDFromJSONBytesUsingIpldPrime([]byte(tc.content))
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, deprecatedAndCorrect, newImpl, tc.name)
|
||||||
|
require.Equal(t, tc.expected, newImpl)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user