Skip to content

Commit

Permalink
Updated README and fixed some compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
0xalank committed Nov 15, 2021
1 parent 5075c77 commit f53e6ef
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 183 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Building `quai` requires both a Go (version 1.14 or later) and a C compiler. You
them using your favourite package manager. Once the dependencies are installed, run

```shell
make quai
make go-quai
```

or, to build the full suite of utilities:
Expand Down
159 changes: 3 additions & 156 deletions cmd/clef/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ import (
"runtime"
"sort"
"strings"
"time"

"github.com/mattn/go-colorable"
"github.com/mattn/go-isatty"
"github.com/spruce-solutions/go-quai/accounts"
"github.com/spruce-solutions/go-quai/accounts/keystore"
"github.com/spruce-solutions/go-quai/cmd/utils"
Expand All @@ -47,15 +48,12 @@ import (
"github.com/spruce-solutions/go-quai/log"
"github.com/spruce-solutions/go-quai/node"
"github.com/spruce-solutions/go-quai/params"
"github.com/spruce-solutions/go-quai/rlp"
"github.com/spruce-solutions/go-quai/rpc"
"github.com/spruce-solutions/go-quai/signer/core"
"github.com/spruce-solutions/go-quai/signer/core/apitypes"
"github.com/spruce-solutions/go-quai/signer/fourbyte"
"github.com/spruce-solutions/go-quai/signer/rules"
"github.com/spruce-solutions/go-quai/signer/storage"
"github.com/mattn/go-colorable"
"github.com/mattn/go-isatty"
"gopkg.in/urfave/cli.v1"
)

Expand Down Expand Up @@ -99,7 +97,7 @@ var (
}
chainIdFlag = cli.Int64Flag{
Name: "chainid",
Value: params.MainnetChainConfig.ChainID.Int64(),
Value: params.MainnetPrimeChainConfig.ChainID.Int64(),
Usage: "Chain id to use for signing (1=mainnet, 3=Ropsten, 4=Rinkeby, 5=Goerli)",
}
rpcPortFlag = cli.IntFlag{
Expand Down Expand Up @@ -695,10 +693,6 @@ func signer(c *cli.Context) error {
}()
}

if c.GlobalBool(testFlag.Name) {
log.Info("Performing UI test")
go testExternalUI(apiImpl)
}
ui.OnSignerStartup(core.StartupInfo{
Info: map[string]interface{}{
"intapi_version": core.InternalAPIVersion,
Expand Down Expand Up @@ -817,153 +811,6 @@ func confirm(text string) bool {
return false
}

func testExternalUI(api *core.SignerAPI) {

ctx := context.WithValue(context.Background(), "remote", "clef binary")
ctx = context.WithValue(ctx, "scheme", "in-proc")
ctx = context.WithValue(ctx, "local", "main")
errs := make([]string, 0)

a := common.HexToAddress("0xdeadbeef000000000000000000000000deadbeef")
addErr := func(errStr string) {
log.Info("Test error", "err", errStr)
errs = append(errs, errStr)
}

queryUser := func(q string) string {
resp, err := api.UI.OnInputRequired(core.UserInputRequest{
Title: "Testing",
Prompt: q,
})
if err != nil {
addErr(err.Error())
}
return resp.Text
}
expectResponse := func(testcase, question, expect string) {
if got := queryUser(question); got != expect {
addErr(fmt.Sprintf("%s: got %v, expected %v", testcase, got, expect))
}
}
expectApprove := func(testcase string, err error) {
if err == nil || err == accounts.ErrUnknownAccount {
return
}
addErr(fmt.Sprintf("%v: expected no error, got %v", testcase, err.Error()))
}
expectDeny := func(testcase string, err error) {
if err == nil || err != core.ErrRequestDenied {
addErr(fmt.Sprintf("%v: expected ErrRequestDenied, got %v", testcase, err))
}
}
var delay = 1 * time.Second
// Test display of info and error
{
api.UI.ShowInfo("If you see this message, enter 'yes' to next question")
time.Sleep(delay)
expectResponse("showinfo", "Did you see the message? [yes/no]", "yes")
api.UI.ShowError("If you see this message, enter 'yes' to the next question")
time.Sleep(delay)
expectResponse("showerror", "Did you see the message? [yes/no]", "yes")
}
{ // Sign data test - clique header
api.UI.ShowInfo("Please approve the next request for signing a clique header")
time.Sleep(delay)
cliqueHeader := types.Header{
ParentHash: common.HexToHash("0000H45H"),
UncleHash: common.HexToHash("0000H45H"),
Coinbase: common.HexToAddress("0000H45H"),
Root: common.HexToHash("0000H00H"),
TxHash: common.HexToHash("0000H45H"),
ReceiptHash: common.HexToHash("0000H45H"),
Difficulty: big.NewInt(1337),
Number: big.NewInt(1337),
GasLimit: 1338,
GasUsed: 1338,
Time: 1338,
Extra: []byte("Extra data Extra data Extra data Extra data Extra data Extra data Extra data Extra data"),
MixDigest: common.HexToHash("0x0000H45H"),
}
cliqueRlp, err := rlp.EncodeToBytes(cliqueHeader)
if err != nil {
utils.Fatalf("Should not error: %v", err)
}
addr, _ := common.NewMixedcaseAddressFromString("0x0011223344556677889900112233445566778899")
_, err = api.SignData(ctx, accounts.MimetypeClique, *addr, hexutil.Encode(cliqueRlp))
expectApprove("signdata - clique header", err)
}
{ // Sign data test - typed data
api.UI.ShowInfo("Please approve the next request for signing EIP-712 typed data")
time.Sleep(delay)
addr, _ := common.NewMixedcaseAddressFromString("0x0011223344556677889900112233445566778899")
data := `{"types":{"EIP712Domain":[{"name":"name","type":"string"},{"name":"version","type":"string"},{"name":"chainId","type":"uint256"},{"name":"verifyingContract","type":"address"}],"Person":[{"name":"name","type":"string"},{"name":"test","type":"uint8"},{"name":"wallet","type":"address"}],"Mail":[{"name":"from","type":"Person"},{"name":"to","type":"Person"},{"name":"contents","type":"string"}]},"primaryType":"Mail","domain":{"name":"Ether Mail","version":"1","chainId":"1","verifyingContract":"0xCCCcccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"},"message":{"from":{"name":"Cow","test":"3","wallet":"0xcD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"},"to":{"name":"Bob","wallet":"0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB","test":"2"},"contents":"Hello, Bob!"}}`
//_, err := api.SignData(ctx, accounts.MimetypeTypedData, *addr, hexutil.Encode([]byte(data)))
var typedData core.TypedData
json.Unmarshal([]byte(data), &typedData)
_, err := api.SignTypedData(ctx, *addr, typedData)
expectApprove("sign 712 typed data", err)
}
{ // Sign data test - plain text
api.UI.ShowInfo("Please approve the next request for signing text")
time.Sleep(delay)
addr, _ := common.NewMixedcaseAddressFromString("0x0011223344556677889900112233445566778899")
_, err := api.SignData(ctx, accounts.MimetypeTextPlain, *addr, hexutil.Encode([]byte("hello world")))
expectApprove("signdata - text", err)
}
{ // Sign data test - plain text reject
api.UI.ShowInfo("Please deny the next request for signing text")
time.Sleep(delay)
addr, _ := common.NewMixedcaseAddressFromString("0x0011223344556677889900112233445566778899")
_, err := api.SignData(ctx, accounts.MimetypeTextPlain, *addr, hexutil.Encode([]byte("hello world")))
expectDeny("signdata - text", err)
}
{ // Sign transaction

api.UI.ShowInfo("Please reject next transaction")
time.Sleep(delay)
data := hexutil.Bytes([]byte{})
to := common.NewMixedcaseAddress(a)
tx := apitypes.SendTxArgs{
Data: &data,
Nonce: 0x1,
Value: hexutil.Big(*big.NewInt(6)),
From: common.NewMixedcaseAddress(a),
To: &to,
GasPrice: (*hexutil.Big)(big.NewInt(5)),
Gas: 1000,
Input: nil,
}
_, err := api.SignTransaction(ctx, tx, nil)
expectDeny("signtransaction [1]", err)
expectResponse("signtransaction [2]", "Did you see any warnings for the last transaction? (yes/no)", "no")
}
{ // Listing
api.UI.ShowInfo("Please reject listing-request")
time.Sleep(delay)
_, err := api.List(ctx)
expectDeny("list", err)
}
{ // Import
api.UI.ShowInfo("Please reject new account-request")
time.Sleep(delay)
_, err := api.New(ctx)
expectDeny("newaccount", err)
}
{ // Metadata
api.UI.ShowInfo("Please check if you see the Origin in next listing (approve or deny)")
time.Sleep(delay)
api.List(context.WithValue(ctx, "Origin", "origin.com"))
expectResponse("metadata - origin", "Did you see origin (origin.com)? [yes/no] ", "yes")
}

for _, e := range errs {
log.Error(e)
}
result := fmt.Sprintf("Tests completed. %d errors:\n%s\n", len(errs), strings.Join(errs, "\n"))
api.UI.ShowInfo(result)

}

type encryptedSeedStorage struct {
Description string `json:"description"`
Version int `json:"version"`
Expand Down
22 changes: 11 additions & 11 deletions cmd/devp2p/internal/ethtest/large.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ func randHash() common.Hash {
func largeHeader() *types.Header {
return &types.Header{
MixDigest: randHash(),
ReceiptHash: randHash(),
TxHash: randHash(),
ReceiptHash: []common.Hash{randHash(), randHash(), randHash()},
TxHash: []common.Hash{randHash(), randHash(), randHash()},
Nonce: types.BlockNonce{},
Extra: []byte{},
Bloom: types.Bloom{},
GasUsed: 0,
Coinbase: common.Address{},
GasLimit: 0,
Extra: make([][]byte, 3),
Bloom: []types.Bloom{types.Bloom{}, types.Bloom{}, types.Bloom{}},
GasUsed: []uint64{0, 0, 0},
Coinbase: []common.Address{common.Address{}, common.Address{}, common.Address{}},
GasLimit: []uint64{0, 0, 0},
UncleHash: types.EmptyUncleHash,
Time: 1337,
ParentHash: randHash(),
Root: randHash(),
Number: largeNumber(2),
Difficulty: largeNumber(2),
ParentHash: []common.Hash{randHash(), randHash(), randHash()},
Root: []common.Hash{randHash(), randHash(), randHash()},
Number: []*big.Int{largeNumber(2), largeNumber(2), largeNumber(2)},
Difficulty: []*big.Int{largeNumber(2), largeNumber(2), largeNumber(2)},
}
}
2 changes: 1 addition & 1 deletion signer/core/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ func (api *SignerAPI) newAccount() (common.Address, error) {
api.UI.ShowError(fmt.Sprintf("Account creation attempt #%d failed due to password requirements: %v", i+1, pwErr))
} else {
// No error
acc, err := be[0].(*keystore.KeyStore).NewAccount(resp.Text)
acc, err := be[0].(*keystore.KeyStore).NewAccount(resp.Text, byte(0))
log.Info("Your new key was generated", "address", acc.Address)
log.Warn("Please backup your key file!", "path", acc.URL.Path)
log.Warn("Please remember your password!")
Expand Down
2 changes: 1 addition & 1 deletion signer/core/signed_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType
// The incoming clique header is already truncated, sent to us with a extradata already shortened
if len(header.Extra) < 65 {
// Need to add it back, to get a suitable length for hashing
newExtra := make([]byte, len(header.Extra)+65)
newExtra := make([][]byte, len(header.Extra)+65)
copy(newExtra, header.Extra)
header.Extra = newExtra
}
Expand Down
26 changes: 13 additions & 13 deletions tests/block_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ func (t *BlockTest) insertBlocks(blockchain *core.BlockChain) ([]btBlock, error)
}

func validateHeader(h *btHeader, h2 *types.Header) error {
if h.Bloom != h2.Bloom {
if h.Bloom != h2.Bloom[0] {
return fmt.Errorf("bloom: want: %x have: %x", h.Bloom, h2.Bloom)
}
if h.Coinbase != h2.Coinbase {
if h.Coinbase != h2.Coinbase[0] {
return fmt.Errorf("coinbase: want: %x have: %x", h.Coinbase, h2.Coinbase)
}
if h.MixHash != h2.MixDigest {
Expand All @@ -239,34 +239,34 @@ func validateHeader(h *btHeader, h2 *types.Header) error {
if h.Nonce != h2.Nonce {
return fmt.Errorf("nonce: want: %x have: %x", h.Nonce, h2.Nonce)
}
if h.Number.Cmp(h2.Number) != 0 {
if h.Number.Cmp(h2.Number[0]) != 0 {
return fmt.Errorf("number: want: %v have: %v", h.Number, h2.Number)
}
if h.ParentHash != h2.ParentHash {
if h.ParentHash != h2.ParentHash[0] {
return fmt.Errorf("parent hash: want: %x have: %x", h.ParentHash, h2.ParentHash)
}
if h.ReceiptTrie != h2.ReceiptHash {
if h.ReceiptTrie != h2.ReceiptHash[0] {
return fmt.Errorf("receipt hash: want: %x have: %x", h.ReceiptTrie, h2.ReceiptHash)
}
if h.TransactionsTrie != h2.TxHash {
if h.TransactionsTrie != h2.TxHash[0] {
return fmt.Errorf("tx hash: want: %x have: %x", h.TransactionsTrie, h2.TxHash)
}
if h.StateRoot != h2.Root {
if h.StateRoot != h2.Root[0] {
return fmt.Errorf("state hash: want: %x have: %x", h.StateRoot, h2.Root)
}
if h.UncleHash != h2.UncleHash {
if h.UncleHash != h2.UncleHash[0] {
return fmt.Errorf("uncle hash: want: %x have: %x", h.UncleHash, h2.UncleHash)
}
if !bytes.Equal(h.ExtraData, h2.Extra) {
if !bytes.Equal(h.ExtraData, h2.Extra[0]) {
return fmt.Errorf("extra data: want: %x have: %x", h.ExtraData, h2.Extra)
}
if h.Difficulty.Cmp(h2.Difficulty) != 0 {
if h.Difficulty.Cmp(h2.Difficulty[0]) != 0 {
return fmt.Errorf("difficulty: want: %v have: %v", h.Difficulty, h2.Difficulty)
}
if h.GasLimit != h2.GasLimit {
if h.GasLimit != h2.GasLimit[0] {
return fmt.Errorf("gasLimit: want: %d have: %d", h.GasLimit, h2.GasLimit)
}
if h.GasUsed != h2.GasUsed {
if h.GasUsed != h2.GasUsed[0] {
return fmt.Errorf("gasUsed: want: %d have: %d", h.GasUsed, h2.GasUsed)
}
if h.Timestamp != h2.Time {
Expand Down Expand Up @@ -306,7 +306,7 @@ func (t *BlockTest) validateImportedHeaders(cm *core.BlockChain, validBlocks []b
// block-by-block, so we can only validate imported headers after
// all blocks have been processed by BlockChain, as they may not
// be part of the longest chain until last block is imported.
for b := cm.CurrentBlock(); b != nil && b.NumberU64() != 0; b = cm.GetBlockByHash(b.Header().ParentHash) {
for b := cm.CurrentBlock(); b != nil && b.NumberU64() != 0; b = cm.GetBlockByHash(b.Header().ParentHash[0]) {
if err := validateHeader(bmap[b.Hash()].BlockHeader, b.Header()); err != nil {
return fmt.Errorf("imported block header validation failed: %v", err)
}
Expand Down

0 comments on commit f53e6ef

Please sign in to comment.