Skip to content

Commit

Permalink
Resolve revocation status using go-schema-processor CredentialStatusR…
Browse files Browse the repository at this point in the history
…esolverRegistry (#55)

Backward incompatible change.

All chain configurations are currently supposed to be passed in the chainConfigs object. If you try to set the deprecated ethereumURL or stateContractAddr fields in the root of the configuration, you will get an error.
  • Loading branch information
olomix authored Feb 27, 2024
1 parent f4c7c42 commit e420c85
Show file tree
Hide file tree
Showing 15 changed files with 292 additions and 900 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: 1.21.1
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tests-c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
runs-on: ubuntu-22.04
container: golang:${{matrix.containers}}
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: |
~/.cache/go-build
Expand All @@ -45,11 +45,11 @@ jobs:
runs-on: macos-12
if: github.event_name == 'push' || github.event_name == 'release'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-go@v3
with:
go-version: 1.21.1
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
~/go/pkg/mod
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ jobs:
runs-on: ubuntu-20.04
container: golang:${{ matrix.containers }}
env:
IPFS_URL: ${{secrets.IPFS_URL }}
IPFS_URL: http://ipfs:5001
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: |
~/.cache/go-build
/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- run: go test -v -race -timeout=60s -find-unused-httpresp ./...
- run: go test -race -timeout=60s -find-unused-httpresp ./...
services:
ipfs:
image: ipfs/kubo:v0.26.0
ports:
- 5001:5001
1 change: 1 addition & 0 deletions badger_cache_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

func TestGetPubRemoteDocument(t *testing.T) {
defer mockBadgerLog(t)()
flushCacheDB()

cacheEng, err := newBadgerCacheEngine()
Expand Down
5 changes: 5 additions & 0 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/dgraph-io/badger/v4"
)

var badgerLogger badger.Logger = nil

var globalDB *badger.DB
var dbCnt int
var dbCond = sync.NewCond(&sync.Mutex{})
Expand Down Expand Up @@ -99,6 +101,9 @@ func openDB() (*badger.DB, error) {
}

opts := badger.DefaultOptions(badgerPath)
if badgerLogger != nil {
opts.Logger = badgerLogger
}

return badger.Open(opts)
}
Expand Down
46 changes: 46 additions & 0 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,47 @@ func doWithBadger(t testing.TB, db *badger.DB) {
require.NoError(t, err)
}

type testBadgerLogger struct {
t testing.TB
silent bool
}

func (t *testBadgerLogger) Errorf(s string, i ...interface{}) {
if t.silent {
return
}
t.t.Errorf("[BADGER ERROR]"+s, i...)
}

func (t *testBadgerLogger) Warningf(s string, i ...interface{}) {
if t.silent {
return
}
t.t.Logf("[BADGER WARNING]"+s, i...)
}

func (t *testBadgerLogger) Infof(s string, i ...interface{}) {
if t.silent {
return
}
t.t.Logf("[BADGER INFO]"+s, i...)
}

func (t *testBadgerLogger) Debugf(s string, i ...interface{}) {
if t.silent {
return
}
t.t.Logf("[BADGER DEBUG]"+s, i...)
}

func mockBadgerLog(t testing.TB) func() {
orig := badgerLogger
badgerLogger = &testBadgerLogger{t, true}
return func() {
badgerLogger = orig
}
}

func BenchmarkBadgerWithOpening(b *testing.B) {
for i := 0; i < b.N; i++ {
func() {
Expand All @@ -58,6 +99,8 @@ func BenchmarkBadgerWithoutOpening(b *testing.B) {
}

func TestBadger(t *testing.T) {
defer mockBadgerLog(t)()

dbPath, err := getBadgerPath()
require.NoError(t, err)

Expand All @@ -71,6 +114,7 @@ func TestBadger(t *testing.T) {
}

func TestGetCacheDB(t *testing.T) {
defer mockBadgerLog(t)()
db1, close1, err := getCacheDB()
require.NoError(t, err)
db2, close2, err := getCacheDB()
Expand Down Expand Up @@ -135,6 +179,7 @@ func set(db *badger.DB, key string, value string) {
}

func TestCleanCache(t *testing.T) {
defer mockBadgerLog(t)()
db1, close1, err := getCacheDB()
require.NoError(t, err)

Expand Down Expand Up @@ -169,6 +214,7 @@ func TestCleanCache(t *testing.T) {
}

func TestMultipleCleanup(t *testing.T) {
defer mockBadgerLog(t)()
_, close1, err := getCacheDB()
require.NoError(t, err)

Expand Down
29 changes: 20 additions & 9 deletions env_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ import (
)

type EnvConfig struct {
DIDMethods []MethodConfig
ChainConfigs PerChainConfig
EthereumURL string // Deprecated: Use ChainConfigs instead
StateContractAddr common.Address // Deprecated: Use ChainConfigs instead
ReverseHashServiceUrl string // Deprecated
IPFSNodeURL string
DIDMethods []MethodConfig
ChainConfigs PerChainConfig
IPFSNodeURL string

// backward incompatible fields, it's an error to use them
EthereumURL string
StateContractAddr string
}

var globalRegistationLock sync.Mutex
var globalRegistrationLock sync.Mutex
var registeredDIDMethods sync.Map

// NewEnvConfigFromJSON returns empty config if input json is nil.
Expand All @@ -36,6 +37,16 @@ func NewEnvConfigFromJSON(in []byte) (EnvConfig, error) {
return cfg, fmt.Errorf("unable to parse json config: %w", err)
}

if cfg.EthereumURL != "" {
return cfg, fmt.Errorf(
"ethereumUrl is deprecated, use chainConfigs instead")
}

if cfg.StateContractAddr != "" {
return cfg, fmt.Errorf(
"stateContractAddr is deprecated, use chainConfigs instead")
}

if len(cfg.DIDMethods) == 0 {
return cfg, nil
}
Expand Down Expand Up @@ -79,8 +90,8 @@ func registerDIDMethods(methodConfigs []MethodConfig) error {
return nil
}

globalRegistationLock.Lock()
defer globalRegistationLock.Unlock()
globalRegistrationLock.Lock()
defer globalRegistrationLock.Unlock()

for _, methodCfg := range newMethodConfigs {
chainIDi := chainIDToInt(methodCfg.ChainID)
Expand Down
7 changes: 1 addition & 6 deletions env_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (

func TestNewEnvConfigFromJSON(t *testing.T) {
cfgJSON := `{
"ethereumUrl": "http://localhost:8545",
"stateContractAddr": "0xEA9aF2088B4a9770fC32A12fD42E61BDD317E655",
"reverseHashServiceUrl": "http://localhost:8003",
"ipfsNodeUrl": "http://localhost:5001",
"chainConfigs": {
Expand Down Expand Up @@ -68,10 +66,7 @@ func TestNewEnvConfigFromJSON(t *testing.T) {
StateContractAddr: common.HexToAddress("0xEA9aF2088B4a9770fC32A12fD42E61BDD317E655"),
},
},
EthereumURL: "http://localhost:8545",
StateContractAddr: common.HexToAddress("0xEA9aF2088B4a9770fC32A12fD42E61BDD317E655"),
ReverseHashServiceUrl: "http://localhost:8003",
IPFSNodeURL: "http://localhost:5001",
IPFSNodeURL: "http://localhost:5001",
},
cfg)

Expand Down
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ go 1.21
require (
github.com/dgraph-io/badger/v4 v4.2.0
github.com/ethereum/go-ethereum v1.13.11
github.com/iden3/contracts-abi/onchain-credential-status-resolver/go/abi v0.0.0-20230911113809-c58b7e7a69b0
github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4
github.com/iden3/go-circuits/v2 v2.0.1
github.com/iden3/go-iden3-core/v2 v2.0.4-0.20240129182142-32180363999b
github.com/iden3/go-iden3-crypto v0.0.15
github.com/iden3/go-merkletree-sql/v2 v2.0.6
github.com/iden3/go-schema-processor/v2 v2.1.3-0.20240116085451-1abc0e6ed115
github.com/iden3/merkletree-proof v0.0.4
github.com/iden3/go-schema-processor/v2 v2.3.0
github.com/iden3/merkletree-proof v0.1.0
github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f
github.com/stretchr/testify v1.8.4
)
Expand Down Expand Up @@ -44,16 +43,15 @@ require (
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/iden3/contracts-abi/onchain-credential-status-resolver/go/abi v0.0.0-20230911113809-c58b7e7a69b0 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.3.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/supranational/blst v0.3.11 // indirect
Expand Down
11 changes: 6 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,14 @@ github.com/iden3/go-iden3-crypto v0.0.15 h1:4MJYlrot1l31Fzlo2sF56u7EVFeHHJkxGXXZ
github.com/iden3/go-iden3-crypto v0.0.15/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E=
github.com/iden3/go-merkletree-sql/v2 v2.0.6 h1:vsVDImnvnHf7Ggr45ptFOXJyWNA/8IwVQO1jzRLUlY8=
github.com/iden3/go-merkletree-sql/v2 v2.0.6/go.mod h1:kRhHKYpui5DUsry5RpveP6IC4XMe6iApdV9VChRYuEk=
github.com/iden3/go-schema-processor/v2 v2.1.3-0.20240116085451-1abc0e6ed115 h1:m0iO7E8RRGgyGzTDcNUmMdHWvv7bS0SVwztCHfNf89U=
github.com/iden3/go-schema-processor/v2 v2.1.3-0.20240116085451-1abc0e6ed115/go.mod h1:Ovsrk0839NZgHtoW4hVLAmHoOsHAQZuVNUXd7sIOkLQ=
github.com/iden3/merkletree-proof v0.0.4 h1:o1XXws6zb7+BBDQYXlo0GPUH+jUY3+GxkT88U1C4Sb8=
github.com/iden3/merkletree-proof v0.0.4/go.mod h1:D49CVDG/tshMiZuDCxWjGJoNplRg9y9XIlg9/eMSYOc=
github.com/iden3/go-schema-processor/v2 v2.3.0 h1:86tnt1myHntcG+9pJ3I+0ycc6V59sITrsPSt0k7/DhU=
github.com/iden3/go-schema-processor/v2 v2.3.0/go.mod h1:BcHVDZyn8q8vUlL+XpOo7hpwXmEjxzO8ao1LkvFsM+k=
github.com/iden3/merkletree-proof v0.1.0 h1:AHmpkbCTLKv1MWWt6YwogB65E4y6UZthbZYPed81w4U=
github.com/iden3/merkletree-proof v0.1.0/go.mod h1:ul0HDU6/eVNX++u/PWScY7pTXiFjqM5kA6vl1wEoTUU=
github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus=
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww=
github.com/jarcoal/httpmock v1.3.1/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
Expand Down Expand Up @@ -320,7 +322,6 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
Expand Down
Loading

0 comments on commit e420c85

Please sign in to comment.