-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests created for the Ethereum Blockchain node providers #277
Changes from 3 commits
15cba86
0b4d49d
01fa58e
13659be
4df584d
3de27fc
f41da6d
849e164
375c811
4abec60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package besu | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/hyperledger/firefly-cli/pkg/types" | ||
"github.com/hyperledger/firefly-common/pkg/fftypes" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewBesuProvider(t *testing.T) { | ||
var ctx context.Context | ||
testCases := []struct { | ||
Name string | ||
Ctx context.Context | ||
Stack *types.Stack | ||
}{ | ||
{ | ||
Name: "testcase1", | ||
Ctx: ctx, | ||
Stack: &types.Stack{ | ||
Name: "TestBesuProviderWithEthconnect", | ||
Members: []*types.Organization{{OrgName: "Org1"}}, | ||
BlockchainProvider: fftypes.FFEnumValue("BlockchainProvider", "EthConnect"), | ||
BlockchainConnector: fftypes.FFEnumValue("BlockchainConnector", "EthConnect"), | ||
BlockchainNodeProvider: fftypes.FFEnumValue("BlockchainNodeProvider", "EthConnect"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be |
||
}, | ||
}, | ||
{ | ||
Name: "testcase2", | ||
Ctx: ctx, | ||
Stack: &types.Stack{ | ||
Members: []*types.Organization{{OrgName: "Org2"}, {OrgName: "org4"}}, | ||
Name: "TestBesuProviderWithEvmconnect", | ||
BlockchainProvider: fftypes.FFEnumValue("BlockchainProvider", "Geth"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be |
||
BlockchainConnector: fftypes.FFEnumValue("BlockchainConnector", "EvmConnect"), | ||
BlockchainNodeProvider: fftypes.FFEnumValue("BlockchainNodeProvider", "Geth"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nguyer thanks for pointing these out i have made adjustments to the testcases, and placed the appropriate values for each field |
||
}, | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
besuProvider := NewBesuProvider(tc.Ctx, tc.Stack) | ||
assert.NotNil(t, besuProvider) | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package besu | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCreateGenesis(t *testing.T) { | ||
//test diferent parameter cases for the CreateGenesis() | ||
testCases := []struct { | ||
Name string | ||
addresses []string | ||
blockPeriod int | ||
chainID int64 | ||
}{ | ||
{ | ||
Name: "testcase1", | ||
addresses: []string{"0xAddress1", "0xAddress2"}, | ||
blockPeriod: 10, | ||
chainID: int64(123), | ||
}, | ||
{ | ||
Name: "testcase2", | ||
addresses: []string{"0xAddress3", "0xAddress4"}, | ||
blockPeriod: 7, | ||
chainID: int64(456), | ||
}, | ||
{ | ||
Name: "testcase3", | ||
addresses: []string{"0xAddress14", "0xAddress29"}, | ||
blockPeriod: 22, | ||
chainID: 345, | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
genesis := CreateGenesis(tc.addresses, tc.blockPeriod, tc.chainID) | ||
extraData := "0x0000000000000000000000000000000000000000000000000000000000000000" | ||
alloc := make(map[string]*Alloc) | ||
for _, address := range tc.addresses { | ||
alloc[address] = &Alloc{ | ||
Balance: "0x200000000000000000000000000000000000000000000000000000000000000", | ||
} | ||
extraData += address | ||
} | ||
extraData = strings.ReplaceAll(fmt.Sprintf("%-236s", extraData), " ", "0") | ||
expectedGenesis := &Genesis{ | ||
Config: &GenesisConfig{ | ||
ChainId: tc.chainID, | ||
ConstantinopleFixBlock: 0, | ||
Clique: &CliqueConfig{ | ||
Blockperiodseconds: tc.blockPeriod, | ||
EpochLength: 30000, | ||
}, | ||
}, | ||
Coinbase: "0x0000000000000000000000000000000000000000", | ||
Difficulty: "0x1", | ||
ExtraData: extraData, | ||
GasLimit: "0xffffffff", | ||
MixHash: "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
Nonce: "0x0", | ||
Timestamp: "0x5c51a607", | ||
Alloc: alloc, | ||
Number: "0x0", | ||
GasUsed: "0x0", | ||
ParentHash: "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
} | ||
// Assert that the generated Genesis is equal to the expected Genesis | ||
assert.Equal(t, expectedGenesis, genesis, "Generated Genesis does not match the expected Genesis") | ||
}) | ||
} | ||
|
||
} | ||
|
||
func TestWriteGenesisJSON(t *testing.T) { | ||
filepath := "testdata" | ||
|
||
testCases := []struct { | ||
Name string | ||
SampleGenesis Genesis | ||
filename string | ||
}{ | ||
{ | ||
Name: "TestCase1", | ||
SampleGenesis: Genesis{ | ||
Config: &GenesisConfig{ | ||
ChainId: int64(456), | ||
ConstantinopleFixBlock: 0, | ||
Clique: &CliqueConfig{ | ||
Blockperiodseconds: 20, | ||
EpochLength: 2000, | ||
}, | ||
}, | ||
}, | ||
filename: filepath + "/genesis1_output.json", | ||
}, | ||
{ | ||
Name: "TestCase2", | ||
SampleGenesis: Genesis{ | ||
Config: &GenesisConfig{ | ||
ChainId: int64(338), | ||
ConstantinopleFixBlock: 0, | ||
Clique: &CliqueConfig{ | ||
Blockperiodseconds: 40, | ||
EpochLength: 4000, | ||
}, | ||
}, | ||
}, | ||
filename: filepath + "/genesis2_output.json", | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
err := tc.SampleGenesis.WriteGenesisJson(tc.filename) | ||
if err != nil { | ||
t.Log("unable to write Genesis JSON", err) | ||
} | ||
// Assert that there is no error | ||
assert.NoError(t, err) | ||
|
||
writtenJSONBytes, err := os.ReadFile(tc.filename) | ||
if err != nil { | ||
t.Log("Unable to write JSON Bytes", err) | ||
} | ||
assert.NoError(t, err) | ||
var writtenGenesis Genesis | ||
|
||
err = json.Unmarshal(writtenJSONBytes, &writtenGenesis) | ||
if err != nil { | ||
t.Log("unable to unmarshal JSON", err) | ||
} | ||
assert.NoError(t, err) | ||
|
||
// Assert that the written Genesis matches the original Genesis | ||
assert.Equal(t, tc.SampleGenesis, writtenGenesis) | ||
}) | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"config": { | ||
"chainId": 456, | ||
"constantinoplefixblock": 0, | ||
"clique": { | ||
"epochlength": 2000, | ||
"blockperiodseconds": 20 | ||
} | ||
}, | ||
"nonce": "", | ||
"timestamp": "", | ||
"extraData": "", | ||
"gasLimit": "", | ||
"difficulty": "", | ||
"mixHash": "", | ||
"coinbase": "", | ||
"alloc": null, | ||
"number": "", | ||
"gasUsed": "", | ||
"parentHash": "" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"config": { | ||
"chainId": 338, | ||
"constantinoplefixblock": 0, | ||
"clique": { | ||
"epochlength": 4000, | ||
"blockperiodseconds": 40 | ||
} | ||
}, | ||
"nonce": "", | ||
"timestamp": "", | ||
"extraData": "", | ||
"gasLimit": "", | ||
"difficulty": "", | ||
"mixHash": "", | ||
"coinbase": "", | ||
"alloc": null, | ||
"number": "", | ||
"gasUsed": "", | ||
"parentHash": "" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
EthConnect
here?EthConnect
is aBlockchainConnector
not aBlockchainProvider