Skip to content

Commit

Permalink
Fix error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolezhniuk committed Dec 6, 2023
1 parent 7d55e56 commit a166dfb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func RegisterChainID(blockchain Blockchain, network NetworkID, chainID int) erro
k := fmt.Sprintf("%s:%s", blockchain, network)
existingChainID, ok := chainIDs[k]
if ok && existingChainID != ChainID(chainID) {
return fmt.Errorf("chainID %s:%s already registered", blockchain, network)
return fmt.Errorf("chainID '%s:%s' already registered with value %d", blockchain, network, existingChainID)
}
chainIDs[k] = ChainID(chainID)

Expand Down
10 changes: 5 additions & 5 deletions did.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ var DIDMethodByte = map[DIDMethod]byte{
func RegisterDIDMethod(m DIDMethod, b byte) error {
existingByte, ok := DIDMethodByte[m]
if ok && existingByte != b {
return fmt.Errorf("DID method %s already registered", m)
return fmt.Errorf("DID method '%s' already registered with byte %b", m, existingByte)
}

max := DIDMethodByte[DIDMethodOther]
Expand Down Expand Up @@ -276,10 +276,10 @@ func RegisterDIDMethodNetwork(params DIDMethodNetworkParams, opts ...Registratio
return err
}
}

if existed, ok := DIDMethodNetwork[m][flg]; ok && existed != params.NetworkFlag {
return fmt.Errorf("DID method network '%s' with blockchain '%s' and network '%s' already registered",
m, b, n)
existedFlag, ok := DIDMethodNetwork[m][flg]
if ok && existedFlag != params.NetworkFlag {
return fmt.Errorf("DID method network '%s' with blockchain '%s' and network '%s' already registered with another flag '%b'",
m, b, n, existedFlag)
}

DIDMethodNetwork[m][flg] = params.NetworkFlag
Expand Down
6 changes: 3 additions & 3 deletions did_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func TestCustomDIDRegistration_Negative(t *testing.T) {
NetworkFlag: 0b0001_0001,
},
opts: []RegistrationOptions{WithChainID(1)},
err: "chainID polygon:mumbai already registered",
err: "chainID 'polygon:mumbai' already registered with value 80001",
},
{
Description: "try to overwrite existing DID method byte",
Expand All @@ -517,7 +517,7 @@ func TestCustomDIDRegistration_Negative(t *testing.T) {
NetworkFlag: 0b00100000 | 0b00000001,
},
opts: []RegistrationOptions{WithChainID(1), WithDIDMethodByte(0b00000010)},
err: "DID method iden3 already registered",
err: "DID method 'iden3' already registered with byte 1",
},
{
Description: "try to write max did method byte",
Expand All @@ -539,7 +539,7 @@ func TestCustomDIDRegistration_Negative(t *testing.T) {
NetworkFlag: 0b00100000 | 0b00000011,
},
opts: nil,
err: "DID method network 'iden3' with blockchain 'eth' and network 'main' already registered",
err: "DID method network 'iden3' with blockchain 'eth' and network 'main' already registered with another flag '100001'",
},
}

Expand Down

0 comments on commit a166dfb

Please sign in to comment.