diff options
-rw-r--r-- | cmd/geth/info_test.json | 2 | ||||
-rw-r--r-- | cmd/geth/js_test.go | 33 | ||||
-rw-r--r-- | common/compiler/solidity.go | 2 | ||||
-rw-r--r-- | common/compiler/solidity_test.go | 30 | ||||
-rw-r--r-- | miner/worker.go | 1 | ||||
-rw-r--r-- | rpc/api_test.go | 20 |
6 files changed, 50 insertions, 38 deletions
diff --git a/cmd/geth/info_test.json b/cmd/geth/info_test.json index 1e0c271ac..63f2163a9 100644 --- a/cmd/geth/info_test.json +++ b/cmd/geth/info_test.json @@ -1 +1 @@ -{"code":"605280600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b60376004356041565b8060005260206000f35b6000600782029050604d565b91905056","info":{"abiDefinition":[{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"multiply","outputs":[{"name":"d","type":"uint256"}],"type":"function"}],"compilerVersion":"0.9.17","developerDoc":{"methods":{}},"language":"Solidity","languageVersion":"0","source":"contract test {\n /// @notice Will multiply `a` by 7.\n function multiply(uint a) returns(uint d) {\n return a * 7;\n }\n}\n","userDoc":{"methods":{"multiply(uint256)":{"notice":"Will multiply `a` by 7."}}}}}
\ No newline at end of file +{"code":"0x605880600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b603d6004803590602001506047565b8060005260206000f35b60006007820290506053565b91905056","info":{"abiDefinition":[{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"multiply","outputs":[{"name":"d","type":"uint256"}],"type":"function"}],"compilerVersion":"0.9.23","developerDoc":{"methods":{}},"language":"Solidity","languageVersion":"0","source":"contract test {\n /// @notice Will multiply `a` by 7.\n function multiply(uint a) returns(uint d) {\n return a * 7;\n }\n}\n","userDoc":{"methods":{"multiply(uint256)":{"notice":"Will multiply `a` by 7."}}}}}
\ No newline at end of file diff --git a/cmd/geth/js_test.go b/cmd/geth/js_test.go index 6368efbfc..2f29612d3 100644 --- a/cmd/geth/js_test.go +++ b/cmd/geth/js_test.go @@ -24,7 +24,7 @@ import ( const ( testSolcPath = "" - solcVersion = "0.9.17" + solcVersion = "0.9.23" testKey = "e6fab74a43941f82d89cb7faa408e227cdad3153c4720e540e855c19b15e6674" testAddress = "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182" @@ -34,6 +34,7 @@ const ( ) var ( + versionRE = regexp.MustCompile(strconv.Quote(`"compilerVersion":"` + solcVersion + `"`)) testGenesis = `{"` + testAddress[2:] + `": {"balance": "` + testBalance + `"}}` ) @@ -246,7 +247,6 @@ func TestSignature(t *testing.T) { } func TestContract(t *testing.T) { - t.Skip() tmp, repl, ethereum := testJEthRE(t) if err := ethereum.Start(); err != nil { @@ -259,7 +259,9 @@ func TestContract(t *testing.T) { var txc uint64 coinbase := common.HexToAddress(testAddress) resolver.New(repl.xeth).CreateContracts(coinbase) + // time.Sleep(1000 * time.Millisecond) + // checkEvalJSON(t, repl, `eth.getBlock("pending", true).transactions.length`, `2`) source := `contract test {\n` + " /// @notice Will multiply `a` by 7." + `\n` + ` function multiply(uint a) returns(uint d) {\n` + @@ -279,10 +281,9 @@ func TestContract(t *testing.T) { // if solc is found with right version, test it, otherwise read from file sol, err := compiler.New("") if err != nil { - t.Logf("solc not found: skipping compiler test") + t.Logf("solc not found: mocking contract compilation step") } else if sol.Version() != solcVersion { - err = fmt.Errorf("solc wrong version found (%v, expect %v): skipping compiler test", sol.Version(), solcVersion) - t.Log(err) + t.Logf("WARNING: solc different version found (%v, test written for %v, may need to update)", sol.Version(), solcVersion) } if err != nil { @@ -298,7 +299,7 @@ func TestContract(t *testing.T) { checkEvalJSON(t, repl, `contract = eth.compile.solidity(source)`, string(contractInfo)) } - checkEvalJSON(t, repl, `contract.code`, `"605280600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b60376004356041565b8060005260206000f35b6000600782029050604d565b91905056"`) + checkEvalJSON(t, repl, `contract.code`, `"0x605880600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b603d6004803590602001506047565b8060005260206000f35b60006007820290506053565b91905056"`) checkEvalJSON( t, repl, @@ -310,13 +311,14 @@ func TestContract(t *testing.T) { Multiply7 = eth.contract(abiDef); multiply7 = new Multiply7(contractaddress); ` - + // time.Sleep(1500 * time.Millisecond) _, err = repl.re.Run(callSetup) if err != nil { - t.Errorf("unexpected error registering, got %v", err) + t.Errorf("unexpected error setting up contract, got %v", err) } - // updatespec + // checkEvalJSON(t, repl, `eth.getBlock("pending", true).transactions.length`, `3`) + // why is this sometimes failing? // checkEvalJSON(t, repl, `multiply7.multiply.call(6)`, `42`) expNotice := "" @@ -324,20 +326,23 @@ multiply7 = new Multiply7(contractaddress); t.Errorf("incorrect confirmation message: expected %v, got %v", expNotice, repl.lastConfirm) } - // why 0? - checkEvalJSON(t, repl, `eth.getBlock("pending", true).transactions.length`, `0`) - txc, repl.xeth = repl.xeth.ApplyTestTxs(repl.stateDb, coinbase, txc) checkEvalJSON(t, repl, `admin.contractInfo.start()`, `true`) checkEvalJSON(t, repl, `multiply7.multiply.sendTransaction(6, { from: primary, gas: "1000000", gasPrice: "100000" })`, `undefined`) - expNotice = `About to submit transaction (no NatSpec info found for contract: content hash not found for '0x4a6c99e127191d2ee302e42182c338344b39a37a47cdbb17ab0f26b6802eb4d1'): {"params":[{"to":"0x5dcaace5982778b409c524873b319667eba5d074","data": "0xc6888fa10000000000000000000000000000000000000000000000000000000000000006"}]}` + expNotice = `About to submit transaction (no NatSpec info found for contract: content hash not found for '0x87e2802265838c7f14bb69eecd2112911af6767907a702eeaa445239fb20711b'): {"params":[{"to":"0x5dcaace5982778b409c524873b319667eba5d074","data": "0xc6888fa10000000000000000000000000000000000000000000000000000000000000006"}]}` if repl.lastConfirm != expNotice { t.Errorf("incorrect confirmation message: expected %v, got %v", expNotice, repl.lastConfirm) } + var contenthash = `"0x86d2b7cf1e72e9a7a3f8d96601f0151742a2f780f1526414304fbe413dc7f9bd"` + if sol != nil { + modContractInfo := versionRE.ReplaceAll(contractInfo, []byte(`"compilerVersion":"`+sol.Version()+`"`)) + _ = modContractInfo + // contenthash = crypto.Sha3(modContractInfo) + } checkEvalJSON(t, repl, `filename = "/tmp/info.json"`, `"/tmp/info.json"`) - checkEvalJSON(t, repl, `contenthash = admin.contractInfo.register(primary, contractaddress, contract, filename)`, `"0x0d067e2dd99a4d8f0c0279738b17130dd415a89f24a23f0e7cf68c546ae3089d"`) + checkEvalJSON(t, repl, `contenthash = admin.contractInfo.register(primary, contractaddress, contract, filename)`, contenthash) checkEvalJSON(t, repl, `admin.contractInfo.registerUrl(primary, contenthash, "file://"+filename)`, `true`) if err != nil { t.Errorf("unexpected error registering, got %v", err) diff --git a/common/compiler/solidity.go b/common/compiler/solidity.go index 6790f9a1d..bc1697692 100644 --- a/common/compiler/solidity.go +++ b/common/compiler/solidity.go @@ -164,7 +164,7 @@ func (sol *Solidity) Compile(source string) (contract *Contract, err error) { err = json.Unmarshal(developerDocJson, &developerDoc) contract = &Contract{ - Code: string(code), + Code: "0x" + string(code), Info: ContractInfo{ Source: source, Language: "Solidity", diff --git a/common/compiler/solidity_test.go b/common/compiler/solidity_test.go index 68e54a7ec..2b0ca148f 100644 --- a/common/compiler/solidity_test.go +++ b/common/compiler/solidity_test.go @@ -9,7 +9,7 @@ import ( "github.com/ethereum/go-ethereum/common" ) -const solcVersion = "0.9.17" +const solcVersion = "0.9.23" var ( source = ` @@ -20,33 +20,37 @@ contract test { } } ` - code = "605280600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b60376004356041565b8060005260206000f35b6000600782029050604d565b91905056" - info = `{"source":"\ncontract test {\n /// @notice Will multiply ` + "`a`" + ` by 7.\n function multiply(uint a) returns(uint d) {\n return a * 7;\n }\n}\n","language":"Solidity","languageVersion":"0","compilerVersion":"0.9.17","abiDefinition":[{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"multiply","outputs":[{"name":"d","type":"uint256"}],"type":"function"}],"userDoc":{"methods":{"multiply(uint256)":{"notice":"Will multiply ` + "`a`" + ` by 7."}}},"developerDoc":{"methods":{}}}` + code = "0x605880600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b603d6004803590602001506047565b8060005260206000f35b60006007820290506053565b91905056" + info = `{"source":"\ncontract test {\n /// @notice Will multiply ` + "`a`" + ` by 7.\n function multiply(uint a) returns(uint d) {\n return a * 7;\n }\n}\n","language":"Solidity","languageVersion":"0","compilerVersion":"0.9.23","abiDefinition":[{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"multiply","outputs":[{"name":"d","type":"uint256"}],"type":"function"}],"userDoc":{"methods":{"multiply(uint256)":{"notice":"Will multiply ` + "`a`" + ` by 7."}}},"developerDoc":{"methods":{}}}` - infohash = common.HexToHash("0x834075768a68e500e459b9c3213750c84de3df47156500cb01bb664d3f88c60a") + infohash = common.HexToHash("0xea782f674eb898e477c20e8a7cf11c2c28b09fa68b5278732104f7a101aed255") ) func TestCompiler(t *testing.T) { sol, err := New("") if err != nil { - t.Skip("no solc installed") + t.Skip("solc not found: skip") + } else if sol.Version() != solcVersion { + t.Logf("WARNING: a newer version of solc found (%v, expect %v)", sol.Version(), solcVersion) } contract, err := sol.Compile(source) if err != nil { t.Errorf("error compiling source. result %v: %v", contract, err) return } - /* - if contract.Code != code { - t.Errorf("wrong code, expected\n%s, got\n%s", code, contract.Code) - } - */ + + if contract.Code != code { + t.Errorf("wrong code, expected\n%s, got\n%s", code, contract.Code) + } + } func TestCompileError(t *testing.T) { sol, err := New("") if err != nil || sol.version != solcVersion { - t.Skip("no solc installed") + t.Skip("solc not found: skip") + } else if sol.Version() != solcVersion { + t.Logf("WARNING: a newer version of solc found (%v, expect %v)", sol.Version(), solcVersion) } contract, err := sol.Compile(source[2:]) if err == nil { @@ -78,11 +82,11 @@ func TestExtractInfo(t *testing.T) { os.Remove(filename) cinfohash, err := ExtractInfo(contract, filename) if err != nil { - t.Errorf("%v", err) + t.Errorf("error extracting info: %v", err) } got, err := ioutil.ReadFile(filename) if err != nil { - t.Errorf("%v", err) + t.Errorf("error reading '%v': %v", filename, err) } if string(got) != info { t.Errorf("incorrect info.json extracted, expected:\n%s\ngot\n%s", info, string(got)) diff --git a/miner/worker.go b/miner/worker.go index 5fa5d3777..5e4ff7510 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -270,6 +270,7 @@ func (self *worker) makeCurrent() { } block.Header().Extra = self.extra + // when 08 is processed ancestors contain 07 (quick block) current := env(block, self.eth) for _, ancestor := range self.chain.GetAncestors(block, 7) { for _, uncle := range ancestor.Uncles() { diff --git a/rpc/api_test.go b/rpc/api_test.go index b49e27bd1..263e9666d 100644 --- a/rpc/api_test.go +++ b/rpc/api_test.go @@ -30,12 +30,15 @@ func TestWeb3Sha3(t *testing.T) { } } +const solcVersion = "0.9.23" + func TestCompileSolidity(t *testing.T) { - t.Skip() solc, err := compiler.New("") if solc == nil { - t.Skip("no solidity compiler") + t.Skip("no solc found: skip") + } else if solc.Version() != solcVersion { + t.Logf("WARNING: solc different version found (%v, test written for %v, may need to update)", solc.Version(), solcVersion) } source := `contract test {\n` + " /// @notice Will multiply `a` by 7." + `\n` + @@ -46,11 +49,11 @@ func TestCompileSolidity(t *testing.T) { jsonstr := `{"jsonrpc":"2.0","method":"eth_compileSolidity","params":["` + source + `"],"id":64}` - //expCode := "605280600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b60376004356041565b8060005260206000f35b6000600782029050604d565b91905056" + expCode := "0x605880600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b603d6004803590602001506047565b8060005260206000f35b60006007820290506053565b91905056" expAbiDefinition := `[{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"multiply","outputs":[{"name":"d","type":"uint256"}],"type":"function"}]` expUserDoc := `{"methods":{"multiply(uint256)":{"notice":"Will multiply ` + "`a`" + ` by 7."}}}` expDeveloperDoc := `{"methods":{}}` - expCompilerVersion := `0.9.13` + expCompilerVersion := solc.Version() expLanguage := "Solidity" expLanguageVersion := "0" expSource := source @@ -76,11 +79,10 @@ func TestCompileSolidity(t *testing.T) { t.Errorf("expected no error, got %v", err) } - /* - if contract.Code != expCode { - t.Errorf("Expected %s got %s", expCode, contract.Code) - } - */ + if contract.Code != expCode { + t.Errorf("Expected \n%s got \n%s", expCode, contract.Code) + } + if strconv.Quote(contract.Info.Source) != `"`+expSource+`"` { t.Errorf("Expected \n'%s' got \n'%s'", expSource, strconv.Quote(contract.Info.Source)) } |