-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into issue/570
- Loading branch information
Showing
43 changed files
with
1,764 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package settings //nolint: dupl | ||
|
||
import ( | ||
"github.com/mailchain/mailchain/cmd/internal/settings/output" | ||
"github.com/mailchain/mailchain/cmd/internal/settings/values" | ||
"github.com/mailchain/mailchain/cmd/mailchain/internal/settings/defaults" | ||
"github.com/mailchain/mailchain/internal/clients/blockscout" | ||
"github.com/mailchain/mailchain/internal/mailbox" | ||
"github.com/mailchain/mailchain/internal/protocols/ethereum" | ||
) | ||
|
||
// BlockscoutPublicKeyFinder configuration settings. | ||
type BlockscoutPublicKeyFinder struct { | ||
EnabledProtocolNetworks values.StringSlice | ||
APIKey values.String | ||
kind string | ||
} | ||
|
||
func blockscoutPublicKeyFinderNoAuth(s values.Store) *BlockscoutPublicKeyFinder { | ||
kind := defaults.ClientBlockscoutNoAuth | ||
|
||
return &BlockscoutPublicKeyFinder{ | ||
kind: kind, | ||
EnabledProtocolNetworks: values.NewDefaultStringSlice( | ||
[]string{"ethereum/" + ethereum.Mainnet}, | ||
s, | ||
"public-key-finders."+kind+".enabled-networks", | ||
), | ||
APIKey: values.NewDefaultString("", s, "public-key-finders."+kind+".api-key"), | ||
} | ||
} | ||
|
||
// Supports a map of what protocol and network combinations are supported. | ||
func (r BlockscoutPublicKeyFinder) Supports() map[string]bool { | ||
m := map[string]bool{} | ||
for _, np := range r.EnabledProtocolNetworks.Get() { | ||
m[np] = true | ||
} | ||
|
||
return m | ||
} | ||
|
||
// Produce `mailbox.PubKeyFinder` based on configuration settings. | ||
func (r BlockscoutPublicKeyFinder) Produce() (mailbox.PubKeyFinder, error) { | ||
return blockscout.NewAPIClient() | ||
} | ||
|
||
// Output configuration as an `output.Element` for use in exporting configuration. | ||
func (r BlockscoutPublicKeyFinder) Output() output.Element { | ||
return output.Element{ | ||
FullName: "public-key-finders." + r.kind, | ||
Attributes: []output.Attribute{ | ||
r.EnabledProtocolNetworks.Attribute(), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package settings | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/mailchain/mailchain/cmd/internal/settings/values" | ||
"github.com/mailchain/mailchain/cmd/internal/settings/values/valuestest" | ||
"github.com/mailchain/mailchain/internal/clients/blockscout" | ||
"github.com/mailchain/mailchain/internal/mailbox" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_blockscoutPublicKeyFinderNoAuth(t *testing.T) { | ||
mockCtrl := gomock.NewController(t) | ||
defer mockCtrl.Finish() | ||
type args struct { | ||
s values.Store | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantEnabledProtocolNetworks []string | ||
}{ | ||
{ | ||
"success", | ||
args{ | ||
func() values.Store { | ||
m := valuestest.NewMockStore(mockCtrl) | ||
m.EXPECT().IsSet("public-key-finders.blockscout-no-auth.enabled-networks").Return(false) | ||
return m | ||
}(), | ||
}, | ||
[]string{"ethereum/mainnet"}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := blockscoutPublicKeyFinderNoAuth(tt.args.s) | ||
assert.Equal(t, tt.wantEnabledProtocolNetworks, got.EnabledProtocolNetworks.Get()) | ||
}) | ||
} | ||
} | ||
|
||
func TestBlockscoutPublicKeyFinder_Supports(t *testing.T) { | ||
mockCtrl := gomock.NewController(t) | ||
defer mockCtrl.Finish() | ||
type fields struct { | ||
EnabledProtocolNetworks values.StringSlice | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
want map[string]bool | ||
}{ | ||
{ | ||
"success", | ||
fields{ | ||
func() values.StringSlice { | ||
m := valuestest.NewMockStringSlice(mockCtrl) | ||
m.EXPECT().Get().Return([]string{"ethereum/mainnet", "ethereum/ropsten"}) | ||
return m | ||
}(), | ||
}, | ||
map[string]bool{"ethereum/mainnet": true, "ethereum/ropsten": true}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
r := BlockscoutPublicKeyFinder{ | ||
EnabledProtocolNetworks: tt.fields.EnabledProtocolNetworks, | ||
} | ||
if got := r.Supports(); !assert.Equal(t, tt.want, got) { | ||
t.Errorf("BlockscoutPublicKeyFinder.Supports() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestBlockscoutPublicKeyFinder_Produce(t *testing.T) { | ||
mockCtrl := gomock.NewController(t) | ||
defer mockCtrl.Finish() | ||
type fields struct { | ||
kind string | ||
EnabledProtocolNetworks values.StringSlice | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
want mailbox.PubKeyFinder | ||
wantErr bool | ||
}{ | ||
{ | ||
"success", | ||
fields{ | ||
"test", | ||
func() values.StringSlice { | ||
m := valuestest.NewMockStringSlice(mockCtrl) | ||
return m | ||
}(), | ||
}, | ||
&blockscout.APIClient{}, | ||
false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
r := BlockscoutPublicKeyFinder{ | ||
kind: tt.fields.kind, | ||
EnabledProtocolNetworks: tt.fields.EnabledProtocolNetworks, | ||
} | ||
got, err := r.Produce() | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("BlockscoutPublicKeyFinder.Produce() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !assert.IsType(t, tt.want, got) { | ||
t.Errorf("BlockscoutPublicKeyFinder.Produce() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.