-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: rodion <[email protected]>
- Loading branch information
1 parent
19cb418
commit aecd489
Showing
7 changed files
with
620 additions
and
28 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,81 @@ | ||
package quorum | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hyperledger/firefly-cli/internal/utils" | ||
"github.com/jarcoal/httpmock" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestUnlockAccount(t *testing.T) { | ||
tests := []struct { | ||
Name string | ||
RPCUrl string | ||
Address string | ||
Password string | ||
StatusCode int | ||
ApiResponse *JSONRPCResponse | ||
}{ | ||
{ | ||
Name: "TestUnlockAccount-1", | ||
RPCUrl: "http://127.0.0.1:8545", | ||
Address: "user-1", | ||
Password: "POST", | ||
StatusCode: 200, | ||
ApiResponse: &JSONRPCResponse{ | ||
JSONRPC: "2.0", | ||
ID: 0, | ||
Error: nil, | ||
Result: "mock result", | ||
}, | ||
}, | ||
{ | ||
Name: "TestUnlockAccountError-2", | ||
RPCUrl: "http://127.0.0.1:8545", | ||
Address: "user-1", | ||
Password: "POST", | ||
StatusCode: 200, | ||
ApiResponse: &JSONRPCResponse{ | ||
JSONRPC: "2.0", | ||
ID: 0, | ||
Error: &JSONRPCError{500, "invalid account"}, | ||
Result: "mock result", | ||
}, | ||
}, | ||
{ | ||
Name: "TestUnlockAccountHTTPError-3", | ||
RPCUrl: "http://localhost:8545", | ||
Address: "user-1", | ||
Password: "POST", | ||
StatusCode: 500, | ||
ApiResponse: &JSONRPCResponse{ | ||
JSONRPC: "2.0", | ||
ID: 0, | ||
Error: nil, | ||
Result: "mock result", | ||
}, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
apiResponse, _ := json.Marshal(tc.ApiResponse) | ||
// mockResponse | ||
httpmock.RegisterResponder("POST", tc.RPCUrl, | ||
httpmock.NewStringResponder(tc.StatusCode, string(apiResponse))) | ||
client := NewQuorumClient(tc.RPCUrl) | ||
utils.StartMockServer(t) | ||
err := client.UnlockAccount(tc.Address, tc.Password) | ||
utils.StopMockServer(t) | ||
|
||
// expect errors when returned status code != 200 or ApiResponse comes back with non nil error | ||
if tc.StatusCode != 200 || tc.ApiResponse.Error != nil { | ||
assert.NotNil(t, err, "expects error to be returned when either quorum returns an application error or non 200 http response") | ||
} else { | ||
assert.NoError(t, err, fmt.Sprintf("unable to unlock account: %v", err)) | ||
} | ||
}) | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
internal/blockchain/ethereum/quorum/private_transaction_manager_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,112 @@ | ||
package quorum | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hyperledger/firefly-cli/internal/log" | ||
"github.com/hyperledger/firefly-cli/pkg/types" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCreateTesseraKeys(t *testing.T) { | ||
ctx := log.WithVerbosity(log.WithLogger(context.Background(), &log.StdoutLogger{}), false) | ||
testCases := []struct { | ||
Name string | ||
Stack *types.Stack | ||
TesseraImage string | ||
KeysPrefix string | ||
KeysName string | ||
}{ | ||
{ | ||
Name: "testcase1", | ||
Stack: &types.Stack{ | ||
Name: "Org-1_quorum", | ||
InitDir: t.TempDir(), | ||
}, | ||
TesseraImage: "quorumengineering/tessera:24.4", | ||
KeysPrefix: "", | ||
KeysName: "tm", | ||
}, | ||
{ | ||
Name: "testcase2", | ||
Stack: &types.Stack{ | ||
Name: "Org-1_quorum", | ||
InitDir: t.TempDir(), | ||
}, | ||
TesseraImage: "quorumengineering/tessera:24.4", | ||
KeysPrefix: "xyz", | ||
KeysName: "tm", | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
privateKey, publicKey, tesseraKeysPath, err := CreateTesseraKeys(ctx, tc.TesseraImage, filepath.Join(tc.Stack.InitDir, "tessera", "tessera_0", "keystore"), tc.KeysPrefix, tc.KeysName) | ||
if err != nil { | ||
t.Log("unable to create tessera keys", err) | ||
} | ||
//validate properties of tessera keys | ||
assert.NotEmpty(t, privateKey) | ||
assert.NotEmpty(t, publicKey) | ||
assert.NotEmpty(t, tesseraKeysPath) | ||
|
||
expectedOutputName := tc.KeysName | ||
if tc.KeysPrefix != "" { | ||
expectedOutputName = fmt.Sprintf("%s_%s", tc.KeysPrefix, expectedOutputName) | ||
} | ||
assert.Equal(t, tesseraKeysPath, filepath.Join(tc.Stack.InitDir, "tessera", "tessera_0", "keystore", expectedOutputName), "invalid output path") | ||
|
||
assert.Nil(t, err) | ||
}) | ||
} | ||
} | ||
|
||
func TestCreateTesseraEntrypoint(t *testing.T) { | ||
ctx := log.WithVerbosity(log.WithLogger(context.Background(), &log.StdoutLogger{}), false) | ||
testCases := []struct { | ||
Name string | ||
Stack *types.Stack | ||
StackName string | ||
MemberCount int | ||
}{ | ||
{ | ||
Name: "testcase1", | ||
Stack: &types.Stack{ | ||
Name: "Org-1_quorum", | ||
InitDir: t.TempDir(), | ||
}, | ||
StackName: "org1", | ||
MemberCount: 4, | ||
}, | ||
{ | ||
Name: "testcase2", | ||
Stack: &types.Stack{ | ||
Name: "Org-2_quorum", | ||
InitDir: t.TempDir(), | ||
}, | ||
StackName: "org2", | ||
MemberCount: 0, | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
err := CreateTesseraEntrypoint(ctx, tc.Stack.InitDir, tc.StackName, tc.MemberCount) | ||
if err != nil { | ||
t.Log("unable to create tessera docker entrypoint", err) | ||
} | ||
path := filepath.Join(tc.Stack.InitDir, "docker-entrypoint.sh") | ||
_, err = os.Stat(path) | ||
assert.NoError(t, err, "docker entrypoint file not created") | ||
|
||
b, err := os.ReadFile(path) | ||
assert.NoError(t, err, "unable to read docker entrypoint file") | ||
for i := 0; i < tc.MemberCount; i++ { | ||
strings.Contains(string(b), fmt.Sprintf("member%dtessera", i)) | ||
} | ||
}) | ||
} | ||
} |
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.