-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #282 from Philip-21/tests
firefly-cli pkg and internal tests
- Loading branch information
Showing
9 changed files
with
829 additions
and
0 deletions.
There are no files selected for viewing
183 changes: 183 additions & 0 deletions
183
internal/blockchain/ethereum/remoterpc/remoterpc_provider_test.go
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,183 @@ | ||
package remoterpc | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/hyperledger/firefly-cli/internal/blockchain/ethereum" | ||
"github.com/hyperledger/firefly-cli/pkg/types" | ||
"github.com/hyperledger/firefly-common/pkg/fftypes" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewRemoteRPCProvider(t *testing.T) { | ||
var ctx context.Context | ||
testCases := []struct { | ||
Name string | ||
Ctx context.Context | ||
Stack *types.Stack | ||
}{ | ||
{ | ||
Name: "testcase-1", | ||
Ctx: ctx, | ||
Stack: &types.Stack{ | ||
Name: "TestRPCwithEvmConnect", | ||
Members: []*types.Organization{ | ||
{ | ||
OrgName: "Org1", | ||
NodeName: "rpc", | ||
Account: ðereum.Account{ | ||
Address: "0x1234567890abcdef0123456789abcdef6789abcd", | ||
PrivateKey: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff", | ||
}, | ||
}, | ||
}, | ||
BlockchainProvider: fftypes.FFEnumValue("BlockchainProvider", "Ethereum"), | ||
BlockchainConnector: fftypes.FFEnumValue("BlockchainConnector", "Evmconnect"), | ||
BlockchainNodeProvider: fftypes.FFEnumValue("BlockchainNodeProvider", "rpc"), | ||
}, | ||
}, | ||
{ | ||
Name: "testcase2", | ||
Ctx: ctx, | ||
Stack: &types.Stack{ | ||
Name: "TestRPCWithEthConnect", | ||
Members: []*types.Organization{ | ||
{ | ||
OrgName: "Org7", | ||
NodeName: "rpc", | ||
Account: ðereum.Account{ | ||
Address: "0x1f2a000000000000000000000000000000000000", | ||
PrivateKey: "aabbccddeeff0011223344556677889900112233445566778899aabbccddeeff", | ||
}, | ||
}, | ||
}, | ||
BlockchainProvider: fftypes.FFEnumValue("BlockchainProvider", "Ethereum"), | ||
BlockchainConnector: fftypes.FFEnumValue("BlockchainConnector", "Ethconnect"), | ||
BlockchainNodeProvider: fftypes.FFEnumValue("BlockchainNodeProvider", "rpc"), | ||
}, | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
rpcProvider := NewRemoteRPCProvider(tc.Ctx, tc.Stack) | ||
assert.NotNil(t, rpcProvider) | ||
}) | ||
} | ||
} | ||
|
||
func TestParseAccount(t *testing.T) { | ||
tests := []struct { | ||
Name string | ||
ExpectedAccount *ethereum.Account | ||
Account map[string]interface{} | ||
}{ | ||
{ | ||
Name: "Account 1", | ||
Account: map[string]interface{}{ | ||
"address": "0x1234567890abcdef0123456789abcdef6789abcd", | ||
"privateKey": "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff", | ||
}, | ||
ExpectedAccount: ðereum.Account{ | ||
Address: "0x1234567890abcdef0123456789abcdef6789abcd", | ||
PrivateKey: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff", | ||
}, | ||
}, | ||
{ | ||
Name: "Account 2", | ||
Account: map[string]interface{}{ | ||
"address": "0x549b5f43a40e1a0522864a004cfff2b0ca473a65", | ||
"privateKey": "112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00", | ||
}, | ||
ExpectedAccount: ðereum.Account{ | ||
Address: "0x549b5f43a40e1a0522864a004cfff2b0ca473a65", | ||
PrivateKey: "112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00", | ||
}, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
p := &RemoteRPCProvider{} | ||
|
||
account := p.ParseAccount(tc.Account) | ||
_, ok := account.(*ethereum.Account) | ||
if !ok { | ||
t.Errorf("Expected result to be of type *ethereum.Account, but got %T", account) | ||
} | ||
assert.Equal(t, tc.ExpectedAccount, account, "Generated account unmatched") | ||
}) | ||
} | ||
} | ||
|
||
func TestGetOrgConfig(t *testing.T) { | ||
testCases := []struct { | ||
Name string | ||
Org *types.Organization | ||
Stack *types.Stack | ||
OrgConfig *types.OrgConfig | ||
}{ | ||
{ | ||
Name: "Testcase1", | ||
Stack: &types.Stack{ | ||
Name: "Org-1", | ||
}, | ||
Org: &types.Organization{ | ||
OrgName: "Org-1", | ||
NodeName: "rpc", | ||
Account: ðereum.Account{ | ||
Address: "0x1234567890abcdef0123456789abcdef6789abcd", | ||
PrivateKey: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff", | ||
}, | ||
}, | ||
OrgConfig: &types.OrgConfig{ | ||
Name: "Org-1", | ||
Key: "0x1234567890abcdef0123456789abcdef6789abcd", | ||
}, | ||
}, | ||
{ | ||
Name: "Testcase2", | ||
Stack: &types.Stack{ | ||
Name: "Org-2", | ||
}, | ||
Org: &types.Organization{ | ||
OrgName: "Org-2", | ||
NodeName: "rpc", | ||
Account: ðereum.Account{ | ||
Address: "0x1f2a000000000000000000000000000000000000", | ||
PrivateKey: "9876543210987654321098765432109876543210987654321098765432109876", | ||
}, | ||
}, | ||
OrgConfig: &types.OrgConfig{ | ||
Name: "Org-2", | ||
Key: "0x1f2a000000000000000000000000000000000000", | ||
}, | ||
}, | ||
{ | ||
Name: "Testcase3", | ||
Stack: &types.Stack{ | ||
Name: "Org-3", | ||
}, | ||
Org: &types.Organization{ | ||
OrgName: "Org-3", | ||
NodeName: "rpc", | ||
Account: ðereum.Account{ | ||
Address: "0xabcdeffedcba9876543210abcdeffedc00000000", | ||
PrivateKey: "aabbccddeeff0011223344556677889900112233445566778899aabbccddeeff", | ||
}, | ||
}, | ||
OrgConfig: &types.OrgConfig{ | ||
Name: "Org-3", | ||
Key: "0xabcdeffedcba9876543210abcdeffedc00000000", | ||
}, | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
p := &RemoteRPCProvider{} | ||
|
||
Orgconfig := p.GetOrgConfig(tc.Stack, tc.Org) | ||
assert.NotNil(t, Orgconfig) | ||
assert.Equal(t, tc.OrgConfig, Orgconfig) | ||
}) | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
internal/blockchain/fabric/fabconnect/fabconnect_config_test.go
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,30 @@ | ||
package fabconnect | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestWriteFabconnectConfig(t *testing.T) { | ||
directory := "testdata" | ||
|
||
testCases := []struct { | ||
Name string | ||
filePath string | ||
}{ | ||
{Name: "TestPath-1", filePath: directory + "/fabconfig1.yaml"}, | ||
{Name: "TestPath-2", filePath: directory + "/fabconfig2.yaml"}, | ||
{Name: "TestPath-3", filePath: directory + "/fabconfig3.yaml"}, | ||
{Name: "TestPath-4", filePath: directory + "/fabconfig4.yaml"}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
err := WriteFabconnectConfig(tc.filePath) | ||
if err != nil { | ||
t.Log("cannot write config:", err) | ||
} | ||
}) | ||
assert.NotNil(t, tc.filePath) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
internal/blockchain/fabric/fabconnect/testdata/fabconfig1.yaml
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,18 @@ | ||
maxinflight: 10 | ||
maxtxwaittime: 60 | ||
sendconcurrency: 25 | ||
receipts: | ||
maxdocs: 1000 | ||
querylimit: 100 | ||
retryinitialdelay: 5 | ||
retrytimeout: 30 | ||
leveldb: | ||
path: /fabconnect/receipts | ||
events: | ||
webhooksAllowPrivateIPs: true | ||
leveldb: | ||
path: /fabconnect/events | ||
http: | ||
port: 3000 | ||
rpc: | ||
configpath: /fabconnect/ccp.yaml |
18 changes: 18 additions & 0 deletions
18
internal/blockchain/fabric/fabconnect/testdata/fabconfig2.yaml
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,18 @@ | ||
maxinflight: 10 | ||
maxtxwaittime: 60 | ||
sendconcurrency: 25 | ||
receipts: | ||
maxdocs: 1000 | ||
querylimit: 100 | ||
retryinitialdelay: 5 | ||
retrytimeout: 30 | ||
leveldb: | ||
path: /fabconnect/receipts | ||
events: | ||
webhooksAllowPrivateIPs: true | ||
leveldb: | ||
path: /fabconnect/events | ||
http: | ||
port: 3000 | ||
rpc: | ||
configpath: /fabconnect/ccp.yaml |
18 changes: 18 additions & 0 deletions
18
internal/blockchain/fabric/fabconnect/testdata/fabconfig3.yaml
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,18 @@ | ||
maxinflight: 10 | ||
maxtxwaittime: 60 | ||
sendconcurrency: 25 | ||
receipts: | ||
maxdocs: 1000 | ||
querylimit: 100 | ||
retryinitialdelay: 5 | ||
retrytimeout: 30 | ||
leveldb: | ||
path: /fabconnect/receipts | ||
events: | ||
webhooksAllowPrivateIPs: true | ||
leveldb: | ||
path: /fabconnect/events | ||
http: | ||
port: 3000 | ||
rpc: | ||
configpath: /fabconnect/ccp.yaml |
18 changes: 18 additions & 0 deletions
18
internal/blockchain/fabric/fabconnect/testdata/fabconfig4.yaml
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,18 @@ | ||
maxinflight: 10 | ||
maxtxwaittime: 60 | ||
sendconcurrency: 25 | ||
receipts: | ||
maxdocs: 1000 | ||
querylimit: 100 | ||
retryinitialdelay: 5 | ||
retrytimeout: 30 | ||
leveldb: | ||
path: /fabconnect/receipts | ||
events: | ||
webhooksAllowPrivateIPs: true | ||
leveldb: | ||
path: /fabconnect/events | ||
http: | ||
port: 3000 | ||
rpc: | ||
configpath: /fabconnect/ccp.yaml |
Oops, something went wrong.