forked from cerc-io/laconicd-deprecated
Compare commits
29 Commits
main
...
all_test_s
Author | SHA1 | Date | |
---|---|---|---|
|
fdfe6ca285 | ||
|
a1ad1e1d35 | ||
|
ff74a447fe | ||
|
0e13bf7702 | ||
|
f8889d0225 | ||
|
c80f690c5d | ||
|
9719b51a12 | ||
|
fa948ec9c2 | ||
|
fb29cc26b2 | ||
|
07435d0597 | ||
|
ec4f8d386d | ||
|
87e873dc18 | ||
|
4867f2a362 | ||
|
2be800f0bb | ||
|
6ac975e213 | ||
|
8973a0fbf3 | ||
|
357f5e8af2 | ||
|
25d1577ce4 | ||
|
cac9fe327c | ||
|
9261699745 | ||
|
15db2d3849 | ||
|
6c597101ea | ||
|
90943bf1e6 | ||
|
512136400d | ||
|
c0662cb5f1 | ||
|
c73dc0d92a | ||
|
8f20f25e43 | ||
|
08e369aa64 | ||
|
40a78c66bf |
2
.github/workflows/docker-image.yml
vendored
2
.github/workflows/docker-image.yml
vendored
@ -1,4 +1,4 @@
|
||||
name: Publish onn release
|
||||
name: Publish on release
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
26
.github/workflows/test.yml
vendored
26
.github/workflows/test.yml
vendored
@ -36,7 +36,7 @@ jobs:
|
||||
- uses: codecov/codecov-action@v3
|
||||
with:
|
||||
file: ./coverage.txt
|
||||
fail_ci_if_error: true
|
||||
fail_ci_if_error: false
|
||||
if: env.GIT_DIFF
|
||||
|
||||
test-importer:
|
||||
@ -81,6 +81,30 @@ jobs:
|
||||
make test-rpc
|
||||
if: env.GIT_DIFF
|
||||
|
||||
sdk_tests:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Checkout laconic-sdk
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
path: "./laconic-sdk/"
|
||||
repository: cerc-io/laconic-sdk
|
||||
fetch-depth: 0
|
||||
ref: jest_timeout
|
||||
- name: Environment
|
||||
run: ls -tlh && env
|
||||
- name: build containers scripts
|
||||
working-directory: tests/sdk_tests
|
||||
run: ./build-laconicd-container.sh && ./build-sdk-test-container.sh
|
||||
- name: start containers
|
||||
working-directory: tests/sdk_tests
|
||||
run: docker compose up -d
|
||||
- name: run-tests.sh
|
||||
working-directory: tests/sdk_tests
|
||||
run: ./run-tests.sh
|
||||
|
||||
|
||||
# integration_tests:
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -50,6 +50,7 @@ coverage.txt
|
||||
sim_log_file
|
||||
tests/**/tmp/*
|
||||
yarn.lock
|
||||
x/auction/client/testutil/bidder-bafyre*
|
||||
|
||||
# Vagrant
|
||||
.vagrant/
|
||||
|
@ -20,7 +20,7 @@ RUN make build
|
||||
FROM alpine:3.17.0
|
||||
|
||||
# Install ca-certificates
|
||||
RUN apk add --update ca-certificates jq
|
||||
RUN apk add --update ca-certificates jq curl
|
||||
WORKDIR /
|
||||
|
||||
# Copy over binaries from the build-env
|
||||
|
@ -47,6 +47,7 @@ WORKDIR /app
|
||||
RUN \
|
||||
git clone https://github.com/cerc-io/laconic-sdk.git \
|
||||
&& cd laconic-sdk \
|
||||
&& git checkout jest_timeout \
|
||||
&& yarn install
|
||||
|
||||
WORKDIR /app/laconic-sdk
|
||||
|
@ -6,7 +6,7 @@ services:
|
||||
volumes:
|
||||
- ../../init.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-nv", "-t1", "--spider", "http://localhost:6060"]
|
||||
test: ["CMD", "curl", "-v", "http://127.0.0.1:6060"]
|
||||
interval: 1s
|
||||
timeout: 5s
|
||||
retries: 30
|
||||
|
@ -9,4 +9,10 @@ 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 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"
|
||||
|
@ -8,17 +8,16 @@ import (
|
||||
"bytes"
|
||||
"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"
|
||||
"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/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"
|
||||
"github.com/ipld/go-ipld-prime/storage/memstore"
|
||||
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).
|
||||
// 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) {
|
||||
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()
|
||||
|
||||
// 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.
|
||||
}}
|
||||
|
||||
// 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!
|
||||
lnk, err := lsys.Store(
|
||||
linking.LinkContext{}, // The zero value is fine. Configure it it you want cancellability or other features.
|
||||
|
35
utils/json_test.go
Normal file
35
utils/json_test.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user