Skip to content

Commit

Permalink
New goldilocks library (#345)
Browse files Browse the repository at this point in the history
* new go-goldilocks version

* tests

* tests

* tests

* tests

* tests cleaning

* tests
  • Loading branch information
error2215 authored Oct 3, 2021
1 parent d910070 commit f00149a
Show file tree
Hide file tree
Showing 23 changed files with 287 additions and 169 deletions.
8 changes: 4 additions & 4 deletions accounts/keystore/account_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ import (
)

var (
addr1, err1 = common.HexToAddress("cb94b11771b0a90d32421b0bca90701f16923c32993c")
addr2, err2 = common.HexToAddress("cb30f22ac2235ef6020516a503ba3c6222a068e65da6")
addr3, err3 = common.HexToAddress("cb22ac06311d367113a9ec35e2f44260b8a55a3753bd")
addr1, err1 = common.HexToAddress("cb27de521e43741cf785cbad450d5649187b9612018f")
addr2, err2 = common.HexToAddress("cb74db416ff2f9c53dabaf34f81142db30350ea7b144")
addr3, err3 = common.HexToAddress("cb65e49851f010cd7d81b5b4969f3b0e8325c415359d")
cachetestDir, _ = filepath.Abs(filepath.Join("testdata", "keystore"))
cachetestAccounts = []accounts.Account{
{
Address: addr1,
URL: accounts.URL{Scheme: KeyStoreScheme, Path: filepath.Join(cachetestDir, "UTC--2020-07-20T17-37-08.515483762Z--cb94b11771b0a90d32421b0bca90701f16923c32993c")},
URL: accounts.URL{Scheme: KeyStoreScheme, Path: filepath.Join(cachetestDir, "UTC--2020-07-20T17-37-08.515483762Z--cb27de521e43741cf785cbad450d5649187b9612018f")},
},
{
Address: addr2,
Expand Down
2 changes: 1 addition & 1 deletion accounts/keystore/testdata/dupes/1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"address":"cb30f22ac2235ef6020516a503ba3c6222a068e65da6","crypto":{"cipher":"aes-128-ctr","ciphertext":"503096539824a2f433950a3e74884c6541fc0e5fed39c6900288646051b26b1549944a09a0fcb59c99c2f7649a587af1a179d8605a0a669953","cipherparams":{"iv":"2e4921d45922d3d09372442be46a88bd"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":4096,"p":6,"r":8,"salt":"7304a0e6dba9a7d6b209eb9d87b7bb747eb983854b09c5e39309934ac6d92c7b"},"mac":"c5cfaf38664d9034c28f6ee79045ae04320a1e0f3892b90f5ae9a4d6475b2b3d"},"id":"2355858f-b495-3d1d-846c-b65ecf3265db","version":3}
{"address":"cb74db416ff2f9c53dabaf34f81142db30350ea7b144","crypto":{"cipher":"aes-128-ctr","ciphertext":"6aa169663d4ab11611d0e6d79988140fe8682fe4a3a201e7ce51678f60c448a2496d45adc1a5c1bd833e4e53daca5b75f3cf71a2e8255b5edd","cipherparams":{"iv":"da8c73f7f222997af20c3e378d8a3e83"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":2,"p":1,"r":8,"salt":"b721d800bd2c0beec1f4d7d44315aa9d6f3c27360d0c965a9e52bd8b27914f96"},"mac":"9dd9f2a178bed1515bb5b64febe194b01d2b6bf48b12ad0485e4538bc1ca1638"},"id":"661fc28b-e59d-4aae-ab34-fb24eb8c51b7","version":3}
2 changes: 1 addition & 1 deletion accounts/keystore/testdata/dupes/2
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"address":"cb30f22ac2235ef6020516a503ba3c6222a068e65da6","crypto":{"cipher":"aes-128-ctr","ciphertext":"503096539824a2f433950a3e74884c6541fc0e5fed39c6900288646051b26b1549944a09a0fcb59c99c2f7649a587af1a179d8605a0a669953","cipherparams":{"iv":"2e4921d45922d3d09372442be46a88bd"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":4096,"p":6,"r":8,"salt":"7304a0e6dba9a7d6b209eb9d87b7bb747eb983854b09c5e39309934ac6d92c7b"},"mac":"c5cfaf38664d9034c28f6ee79045ae04320a1e0f3892b90f5ae9a4d6475b2b3d"},"id":"2355858f-b495-3d1d-846c-b65ecf3265db","version":3}
{"address":"cb74db416ff2f9c53dabaf34f81142db30350ea7b144","crypto":{"cipher":"aes-128-ctr","ciphertext":"6aa169663d4ab11611d0e6d79988140fe8682fe4a3a201e7ce51678f60c448a2496d45adc1a5c1bd833e4e53daca5b75f3cf71a2e8255b5edd","cipherparams":{"iv":"da8c73f7f222997af20c3e378d8a3e83"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":2,"p":1,"r":8,"salt":"b721d800bd2c0beec1f4d7d44315aa9d6f3c27360d0c965a9e52bd8b27914f96"},"mac":"9dd9f2a178bed1515bb5b64febe194b01d2b6bf48b12ad0485e4538bc1ca1638"},"id":"661fc28b-e59d-4aae-ab34-fb24eb8c51b7","version":3}
2 changes: 1 addition & 1 deletion accounts/keystore/testdata/dupes/foo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"address":"cb94b11771b0a90d32421b0bca90701f16923c32993c","crypto":{"cipher":"aes-128-ctr","ciphertext":"a957bbbe79d4257a363eaf905cdd73e6d5289704b8044abf9af2b26fd0137320b6fb54fd1052126da2b5b08d6899e352d3ffc8284875f0dd27","cipherparams":{"iv":"a7415a7526fbf1938f5ed7c33c0881b6"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":4096,"p":6,"r":8,"salt":"f7bd40793e404cb4b0d47c63c64b4cae2558c5729206d4bd949de870924d9d9c"},"mac":"16dbfa4706278ad026316205cffaad9a1cc3573a86ba2ec233079c8cd8a85e8c"},"id":"2355858f-b495-3d1d-846c-b65ecf3265db","version":3}
{"address":"cb27de521e43741cf785cbad450d5649187b9612018f","crypto":{"cipher":"aes-128-ctr","ciphertext":"13b3adc4203f236343e7c6a59c04ac56e6dee12258eba391697d2b5f1e9b87698f53ae12b5837bc906c42bce38f9b575ea82dfaef84b1d6795","cipherparams":{"iv":"ce4b6edebbcb44c76ba42cb2c7a59dd3"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":2,"p":1,"r":8,"salt":"54eeca614269586df5dfbde87b39e4077b0353d23fe3fb0e72312973b8d4d3df"},"mac":"d7450eab867cc3b4f7619a586878428cf2a73056fcae32cc605df8ce07e799f6"},"id":"84c5fc55-b541-42ed-aaa7-28f508cd85c0","version":3}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"cb27de521e43741cf785cbad450d5649187b9612018f","crypto":{"cipher":"aes-128-ctr","ciphertext":"13b3adc4203f236343e7c6a59c04ac56e6dee12258eba391697d2b5f1e9b87698f53ae12b5837bc906c42bce38f9b575ea82dfaef84b1d6795","cipherparams":{"iv":"ce4b6edebbcb44c76ba42cb2c7a59dd3"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":2,"p":1,"r":8,"salt":"54eeca614269586df5dfbde87b39e4077b0353d23fe3fb0e72312973b8d4d3df"},"mac":"d7450eab867cc3b4f7619a586878428cf2a73056fcae32cc605df8ce07e799f6"},"id":"84c5fc55-b541-42ed-aaa7-28f508cd85c0","version":3}

This file was deleted.

2 changes: 1 addition & 1 deletion accounts/keystore/testdata/keystore/aaa
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"address":"cb30f22ac2235ef6020516a503ba3c6222a068e65da6","crypto":{"cipher":"aes-128-ctr","ciphertext":"503096539824a2f433950a3e74884c6541fc0e5fed39c6900288646051b26b1549944a09a0fcb59c99c2f7649a587af1a179d8605a0a669953","cipherparams":{"iv":"2e4921d45922d3d09372442be46a88bd"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":4096,"p":6,"r":8,"salt":"7304a0e6dba9a7d6b209eb9d87b7bb747eb983854b09c5e39309934ac6d92c7b"},"mac":"c5cfaf38664d9034c28f6ee79045ae04320a1e0f3892b90f5ae9a4d6475b2b3d"},"id":"2355858f-b495-3d1d-846c-b65ecf3265db","version":3}
{"address":"cb74db416ff2f9c53dabaf34f81142db30350ea7b144","crypto":{"cipher":"aes-128-ctr","ciphertext":"6aa169663d4ab11611d0e6d79988140fe8682fe4a3a201e7ce51678f60c448a2496d45adc1a5c1bd833e4e53daca5b75f3cf71a2e8255b5edd","cipherparams":{"iv":"da8c73f7f222997af20c3e378d8a3e83"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":2,"p":1,"r":8,"salt":"b721d800bd2c0beec1f4d7d44315aa9d6f3c27360d0c965a9e52bd8b27914f96"},"mac":"9dd9f2a178bed1515bb5b64febe194b01d2b6bf48b12ad0485e4538bc1ca1638"},"id":"661fc28b-e59d-4aae-ab34-fb24eb8c51b7","version":3}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"address":"cb22ac06311d367113a9ec35e2f44260b8a55a3753bd","crypto":{"cipher":"aes-128-ctr","ciphertext":"8e9e0fcc11168c54a489d541e046ba138d15f862754de5df80c2289dc7b8fcb3c9d0fd47935dd3b7b33fe401cbf1aa763016dbdef62b5bfc81","cipherparams":{"iv":"0faaa611faa95ddda4305271549b752f"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":4096,"p":6,"r":8,"salt":"ca2dc8495121a90d09e4dc193b39a83b0d98307d7e64a684bed845eff1e5f35c"},"mac":"73d82db94ad659a7ef8398a98ebc2cca856df01c0d8c1cdad4b67bad9c85ace7"},"id":"2355858f-b495-3d1d-846c-b65ecf3265db","version":3}
{"address":"cb65e49851f010cd7d81b5b4969f3b0e8325c415359d","crypto":{"cipher":"aes-128-ctr","ciphertext":"e3baf22fc47c32bfb60c366f7420e6ec3c4e67304cffbe2eefda0b534cca7234a4e259c78c5d6af12793b131fa5c5e5edfd5654e9176a984d3","cipherparams":{"iv":"2c50c7de1792298229e7857c24f8b88e"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":2,"p":1,"r":8,"salt":"1d960f43650c0633c42e111a84a44dfcb765a6ceb6c852592919a9c594e65387"},"mac":"80a0d1857a0baed49df9df93bcd7369d45ca9aeba54a6075800c59e49a7dfe70"},"id":"7220fd89-0227-4014-b55e-92abdfecf500","version":3}
2 changes: 1 addition & 1 deletion accounts/keystore/testdata/keystore/zzz
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"address":"cb22ac06311d367113a9ec35e2f44260b8a55a3753bd","crypto":{"cipher":"aes-128-ctr","ciphertext":"8e9e0fcc11168c54a489d541e046ba138d15f862754de5df80c2289dc7b8fcb3c9d0fd47935dd3b7b33fe401cbf1aa763016dbdef62b5bfc81","cipherparams":{"iv":"0faaa611faa95ddda4305271549b752f"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":4096,"p":6,"r":8,"salt":"ca2dc8495121a90d09e4dc193b39a83b0d98307d7e64a684bed845eff1e5f35c"},"mac":"73d82db94ad659a7ef8398a98ebc2cca856df01c0d8c1cdad4b67bad9c85ace7"},"id":"2355858f-b495-3d1d-846c-b65ecf3265db","version":3}
{"address":"cb65e49851f010cd7d81b5b4969f3b0e8325c415359d","crypto":{"cipher":"aes-128-ctr","ciphertext":"e3baf22fc47c32bfb60c366f7420e6ec3c4e67304cffbe2eefda0b534cca7234a4e259c78c5d6af12793b131fa5c5e5edfd5654e9176a984d3","cipherparams":{"iv":"2c50c7de1792298229e7857c24f8b88e"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":2,"p":1,"r":8,"salt":"1d960f43650c0633c42e111a84a44dfcb765a6ceb6c852592919a9c594e65387"},"mac":"80a0d1857a0baed49df9df93bcd7369d45ca9aeba54a6075800c59e49a7dfe70"},"id":"7220fd89-0227-4014-b55e-92abdfecf500","version":3}
54 changes: 27 additions & 27 deletions cmd/gocore/accountcmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ func TestAccountList(t *testing.T) {
defer gocore.ExpectExit()
if runtime.GOOS == "windows" {
gocore.Expect(`
Account #0: {cb94b11771b0a90d32421b0bca90701f16923c32993c} keystore://{{.Datadir}}\keystore\UTC--2020-07-20T17-37-08.515483762Z--cb94b11771b0a90d32421b0bca90701f16923c32993c
Account #1: {cb30f22ac2235ef6020516a503ba3c6222a068e65da6} keystore://{{.Datadir}}\keystore\aaa
Account #2: {cb22ac06311d367113a9ec35e2f44260b8a55a3753bd} keystore://{{.Datadir}}\keystore\zzz
Account #0: {cb27de521e43741cf785cbad450d5649187b9612018f} keystore://{{.Datadir}}\keystore\UTC--2020-07-20T17-37-08.515483762Z--cb27de521e43741cf785cbad450d5649187b9612018f
Account #1: {cb74db416ff2f9c53dabaf34f81142db30350ea7b144} keystore://{{.Datadir}}\keystore\aaa
Account #2: {cb65e49851f010cd7d81b5b4969f3b0e8325c415359d} keystore://{{.Datadir}}\keystore\zzz
`)
} else {
gocore.Expect(`
Account #0: {cb94b11771b0a90d32421b0bca90701f16923c32993c} keystore://{{.Datadir}}/keystore/UTC--2020-07-20T17-37-08.515483762Z--cb94b11771b0a90d32421b0bca90701f16923c32993c
Account #1: {cb30f22ac2235ef6020516a503ba3c6222a068e65da6} keystore://{{.Datadir}}/keystore/aaa
Account #2: {cb22ac06311d367113a9ec35e2f44260b8a55a3753bd} keystore://{{.Datadir}}/keystore/zzz
Account #0: {cb27de521e43741cf785cbad450d5649187b9612018f} keystore://{{.Datadir}}/keystore/UTC--2020-07-20T17-37-08.515483762Z--cb27de521e43741cf785cbad450d5649187b9612018f
Account #1: {cb74db416ff2f9c53dabaf34f81142db30350ea7b144} keystore://{{.Datadir}}/keystore/aaa
Account #2: {cb65e49851f010cd7d81b5b4969f3b0e8325c415359d} keystore://{{.Datadir}}/keystore/zzz
`)
}
}
Expand Down Expand Up @@ -104,10 +104,10 @@ func TestAccountUpdate(t *testing.T) {
datadir := tmpDatadirWithKeystore(t)
gocore := runGocore(t, "account", "update",
"--datadir", datadir, "--lightkdf",
"cb22ac06311d367113a9ec35e2f44260b8a55a3753bd")
"cb65e49851f010cd7d81b5b4969f3b0e8325c415359d")
defer gocore.ExpectExit()
gocore.Expect(`
Unlocking account cb22ac06311d367113a9ec35e2f44260b8a55a3753bd | Attempt 1/3
Unlocking account cb65e49851f010cd7d81b5b4969f3b0e8325c415359d | Attempt 1/3
!! Unsupported terminal, password will be echoed.
Password: {{.InputLine "foobar"}}
Please give a new password. Do not forget this password.
Expand Down Expand Up @@ -146,18 +146,18 @@ func TestUnlockFlag(t *testing.T) {
datadir := tmpDatadirWithKeystore(t)
gocore := runGocore(t,
"--datadir", datadir, "--nat", "none", "--nodiscover", "--maxpeers", "0", "--port", "0",
"--unlock", "cb22ac06311d367113a9ec35e2f44260b8a55a3753bd",
"--unlock", "cb65e49851f010cd7d81b5b4969f3b0e8325c415359d",
"js", "testdata/empty.js")
gocore.Expect(`
Unlocking account cb22ac06311d367113a9ec35e2f44260b8a55a3753bd | Attempt 1/3
Unlocking account cb65e49851f010cd7d81b5b4969f3b0e8325c415359d | Attempt 1/3
!! Unsupported terminal, password will be echoed.
Password: {{.InputLine "foobar"}}
`)
gocore.ExpectExit()

wantMessages := []string{
"Unlocked account",
"=cb22ac06311d367113a9ec35e2f44260b8a55a3753bd",
"=cb65e49851f010cd7d81b5b4969f3b0e8325c415359d",
}
for _, m := range wantMessages {
if !strings.Contains(gocore.StderrText(), m) {
Expand All @@ -170,17 +170,17 @@ func TestUnlockFlagWrongPassword(t *testing.T) {
datadir := tmpDatadirWithKeystore(t)
gocore := runGocore(t,
"--datadir", datadir, "--nat", "none", "--nodiscover", "--maxpeers", "0", "--port", "0",
"--unlock", "cb22ac06311d367113a9ec35e2f44260b8a55a3753bd")
"--unlock", "cb65e49851f010cd7d81b5b4969f3b0e8325c415359d")
defer gocore.ExpectExit()
gocore.Expect(`
Unlocking account cb22ac06311d367113a9ec35e2f44260b8a55a3753bd | Attempt 1/3
Unlocking account cb65e49851f010cd7d81b5b4969f3b0e8325c415359d | Attempt 1/3
!! Unsupported terminal, password will be echoed.
Password: {{.InputLine "foobar1"}}
Unlocking account cb22ac06311d367113a9ec35e2f44260b8a55a3753bd | Attempt 2/3
Unlocking account cb65e49851f010cd7d81b5b4969f3b0e8325c415359d | Attempt 2/3
Password: {{.InputLine "foobar1"}}
Unlocking account cb22ac06311d367113a9ec35e2f44260b8a55a3753bd | Attempt 3/3
Unlocking account cb65e49851f010cd7d81b5b4969f3b0e8325c415359d | Attempt 3/3
Password: {{.InputLine "foobar1"}}
Fatal: Failed to unlock account cb22ac06311d367113a9ec35e2f44260b8a55a3753bd (could not decrypt key with given password)
Fatal: Failed to unlock account cb65e49851f010cd7d81b5b4969f3b0e8325c415359d (could not decrypt key with given password)
`)
}

Expand All @@ -202,8 +202,8 @@ Password: {{.InputLine "foobar"}}

wantMessages := []string{
"Unlocked account",
"=cb94b11771b0a90d32421b0bca90701f16923c32993c",
"=cb22ac06311d367113a9ec35e2f44260b8a55a3753bd",
"=cb27de521e43741cf785cbad450d5649187b9612018f",
"=cb65e49851f010cd7d81b5b4969f3b0e8325c415359d",
}
for _, m := range wantMessages {
if !strings.Contains(gocore.StderrText(), m) {
Expand All @@ -222,8 +222,8 @@ func TestUnlockFlagPasswordFile(t *testing.T) {

wantMessages := []string{
"Unlocked account",
"=cb94b11771b0a90d32421b0bca90701f16923c32993c",
"=cb22ac06311d367113a9ec35e2f44260b8a55a3753bd",
"=cb27de521e43741cf785cbad450d5649187b9612018f",
"=cb65e49851f010cd7d81b5b4969f3b0e8325c415359d",
}
for _, m := range wantMessages {
if !strings.Contains(gocore.StderrText(), m) {
Expand All @@ -247,7 +247,7 @@ func TestUnlockFlagAmbiguous(t *testing.T) {
store := filepath.Join("..", "..", "accounts", "keystore", "testdata", "dupes")
gocore := runGocore(t,
"--keystore", store, "--nat", "none", "--nodiscover", "--maxpeers", "0", "--port", "0",
"--unlock", "cb30f22ac2235ef6020516a503ba3c6222a068e65da6",
"--unlock", "cb74db416ff2f9c53dabaf34f81142db30350ea7b144",
"js", "testdata/empty.js")
defer gocore.ExpectExit()

Expand All @@ -257,10 +257,10 @@ func TestUnlockFlagAmbiguous(t *testing.T) {
return abs
})
gocore.Expect(`
Unlocking account cb30f22ac2235ef6020516a503ba3c6222a068e65da6 | Attempt 1/3
Unlocking account cb74db416ff2f9c53dabaf34f81142db30350ea7b144 | Attempt 1/3
!! Unsupported terminal, password will be echoed.
Password: {{.InputLine "foobar"}}
Multiple key files exist for address cb30f22ac2235ef6020516a503ba3c6222a068e65da6:
Multiple key files exist for address cb74db416ff2f9c53dabaf34f81142db30350ea7b144:
keystore://{{keypath "1"}}
keystore://{{keypath "2"}}
Testing your password against all of them...
Expand All @@ -272,7 +272,7 @@ In order to avoid this warning, you need to remove the following duplicate key f

wantMessages := []string{
"Unlocked account",
"=cb30f22ac2235ef6020516a503ba3c6222a068e65da6",
"=cb74db416ff2f9c53dabaf34f81142db30350ea7b144",
}
for _, m := range wantMessages {
if !strings.Contains(gocore.StderrText(), m) {
Expand All @@ -285,7 +285,7 @@ func TestUnlockFlagAmbiguousWrongPassword(t *testing.T) {
store := filepath.Join("..", "..", "accounts", "keystore", "testdata", "dupes")
gocore := runGocore(t,
"--keystore", store, "--nat", "none", "--nodiscover", "--maxpeers", "0", "--port", "0",
"--unlock", "cb30f22ac2235ef6020516a503ba3c6222a068e65da6")
"--unlock", "cb74db416ff2f9c53dabaf34f81142db30350ea7b144")
defer gocore.ExpectExit()

// Helper for the expect template, returns absolute keystore path.
Expand All @@ -294,10 +294,10 @@ func TestUnlockFlagAmbiguousWrongPassword(t *testing.T) {
return abs
})
gocore.Expect(`
Unlocking account cb30f22ac2235ef6020516a503ba3c6222a068e65da6 | Attempt 1/3
Unlocking account cb74db416ff2f9c53dabaf34f81142db30350ea7b144 | Attempt 1/3
!! Unsupported terminal, password will be echoed.
Password: {{.InputLine "wrong"}}
Multiple key files exist for address cb30f22ac2235ef6020516a503ba3c6222a068e65da6:
Multiple key files exist for address cb74db416ff2f9c53dabaf34f81142db30350ea7b144:
keystore://{{keypath "1"}}
keystore://{{keypath "2"}}
Testing your password against all of them...
Expand Down
Loading

0 comments on commit f00149a

Please sign in to comment.