mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56:43 +00:00
synced up to go-ethereum 1.5.0-unstable develop branch major features: * api overhaul due to rpc v2 and node service stack interface changes * blockchain/ethereum contract interaction rewritten using abi/abigen (chequebook, ens) * swarm - cluster control CLI - migration and revamp of prehistoric eth-utils repo * poor man's end to end testing: scripted scenarios in swarm/test using swarm CLI * http proxy now handles 3 url schemes for 1) ens-enabled [bzz], 2) immutable [bzzi] and 3) raw manifest [bzzr] resolution * fixes issues with remote address setting, forwarding and syncing * new control flags to switch swap and sync on and off * placeholder basic implementation Ethereum Name Service regression: * uri based versioning support is dropped temporarily since state tree pruning does not guarantee historical record * registrar related functionality temporarily restricted - current ENS provides basic free and unrestricted Register/Resolve accounts/abi: * bind: repeated attempt deployment of contracts, validation against known code, transactor creation from private keys * accountmanager: getUnlocked snatch private key when unlocked cmd: * unlockAccount moved to utils/cmd and exported * getPassPhrase moved to utils/input and exported * accountcmds: reflect the change * js: GlobalRegistrar is dropped (ens) flags: * chequebook, bzzaccount, bzzport, bzzconfig, bzznoswap, bzznosync chequebook: * move from common/ to swarm/services * abigen-ised * specifies its own API (removed chequebook api from swarm/api) kademlia: * move from common to swarm/network/kademlia * address abstracted out to separate file + tests dns/ens/registrar: * moved from swarm/api to swarm/services/ens * implementation is basic placeholder before ENS is implemented * temporary rpc api via ens namespace * the old common/registrar is removed (also from eth/backend apis) swap: * the abstract swap module moved from common to swarm/services * now embedded in the swarm and chequebook specific setup (this will change) * safer chequebook deployment using abigen helpers eth: * public accessor for GPO, needed to construct a PublicBlockChainAPI * extends ContractBackend in eth/bind.go with BalanceAt, GetTxReceipt and CodeAt API calls internal/web3ext * add js bindings for bzz, chequebook rpc apis swarm/api: * refactored api into smaller modules filesystem/storage/testapi * ethereum backend (needed for dns, swap, etc) moved to abi/bind swarm/api/http: * now supports the 3 uri schemes * examples/album updated swarm/cmd: * migrate old eth-utils and modify into a cluster control CLI * bzzup now allows non-local gateway, endpoint specified as second argument swarm/network: * forwarder improved log messages, fixup condition on whether syncer is nil * hive extended with controls for testing support block read/write, swap/sync enabled/disabled * hive keepAlive launches with alarm in case no discover and no kaddb * fix IP address formatting issue [::1] -> became ::1 which refused to dial, now use discover.NewNode#String * integrate functionality for enabling/disabling sync and swap * allow nil sync state - improve syncer interface in protocol swarm/test * poor man's testing framework. scripts invoking swarm/cmd/swarm * added tests for basic scenarios connections, swap, sync swarm: * rewrite api using rpc v2 * blockchain comms via abi/abigen + eth.ContractBackend * integrate new flags
176 lines
4.7 KiB
Go
176 lines
4.7 KiB
Go
package api
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path"
|
|
"runtime"
|
|
"testing"
|
|
)
|
|
|
|
var (
|
|
testDir string
|
|
testDownloadDir string
|
|
)
|
|
|
|
func init() {
|
|
_, filename, _, _ := runtime.Caller(1)
|
|
testDir = path.Join(path.Dir(filename), "../test")
|
|
testDownloadDir, _ = ioutil.TempDir(os.TempDir(), "bzz-test")
|
|
}
|
|
|
|
func testFileSystem(t *testing.T, f func(*FileSystem)) {
|
|
testApi(t, func(api *Api) {
|
|
f(NewFileSystem(api))
|
|
})
|
|
}
|
|
|
|
func readPath(t *testing.T, parts ...string) string {
|
|
// func readPath(t *testing.T, parts ...string) []byte {
|
|
file := path.Join(parts...)
|
|
content, err := ioutil.ReadFile(file)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error reading '%v': %v", file, err)
|
|
}
|
|
return string(content)
|
|
}
|
|
|
|
func TestApiDirUpload0(t *testing.T) {
|
|
// t.Skip("FIXME")
|
|
testFileSystem(t, func(fs *FileSystem) {
|
|
api := fs.api
|
|
bzzhash, err := fs.Upload(path.Join(testDir, "test0"), "")
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
content := readPath(t, testDir, "test0", "index.html")
|
|
resp := testGet(t, api, bzzhash+"/index.html")
|
|
exp := expResponse(content, "text/html; charset=utf-8", 0)
|
|
checkResponse(t, resp, exp)
|
|
|
|
content = readPath(t, testDir, "test0", "index.css")
|
|
resp = testGet(t, api, bzzhash+"/index.css")
|
|
exp = expResponse(content, "text/css", 0)
|
|
checkResponse(t, resp, exp)
|
|
|
|
content = readPath(t, testDir, "test0", "img", "logo.png")
|
|
resp = testGet(t, api, bzzhash+"/img/logo.png")
|
|
exp = expResponse(content, "image/png", 0)
|
|
|
|
_, _, _, err = api.Get(bzzhash, true)
|
|
if err == nil {
|
|
t.Fatalf("expected error: %v", err)
|
|
}
|
|
|
|
downloadDir := path.Join(testDownloadDir, "test0")
|
|
os.RemoveAll(downloadDir)
|
|
defer os.RemoveAll(downloadDir)
|
|
err = fs.Download(bzzhash, downloadDir)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
newbzzhash, err := fs.Upload(downloadDir, "")
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if bzzhash != newbzzhash {
|
|
t.Fatalf("download %v reuploaded has incorrect hash, expected %v, got %v", downloadDir, bzzhash, newbzzhash)
|
|
}
|
|
|
|
})
|
|
}
|
|
|
|
func TestApiDirUploadModify(t *testing.T) {
|
|
// t.Skip("FIXME")
|
|
testFileSystem(t, func(fs *FileSystem) {
|
|
api := fs.api
|
|
bzzhash, err := fs.Upload(path.Join(testDir, "test0"), "")
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
return
|
|
}
|
|
|
|
bzzhash, err = api.Modify(bzzhash+"/index.html", "", "", true)
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
return
|
|
}
|
|
bzzhash, err = api.Modify(bzzhash+"/index2.html", "9ea1f60ebd80786d6005f6b256376bdb494a82496cd86fe8c307cdfb23c99e71", "text/html; charset=utf-8", true)
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
return
|
|
}
|
|
bzzhash, err = api.Modify(bzzhash+"/img/logo.png", "9ea1f60ebd80786d6005f6b256376bdb494a82496cd86fe8c307cdfb23c99e71", "text/html; charset=utf-8", true)
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
return
|
|
}
|
|
|
|
content := readPath(t, testDir, "test0", "index.html")
|
|
resp := testGet(t, api, bzzhash+"/index2.html")
|
|
exp := expResponse(content, "text/html; charset=utf-8", 0)
|
|
checkResponse(t, resp, exp)
|
|
|
|
resp = testGet(t, api, bzzhash+"/img/logo.png")
|
|
exp = expResponse(content, "text/html; charset=utf-8", 0)
|
|
checkResponse(t, resp, exp)
|
|
|
|
content = readPath(t, testDir, "test0", "index.css")
|
|
resp = testGet(t, api, bzzhash+"/index.css")
|
|
exp = expResponse(content, "text/css", 0)
|
|
|
|
_, _, _, err = api.Get(bzzhash, true)
|
|
if err == nil {
|
|
t.Errorf("expected error: %v", err)
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestApiDirUploadWithRootFile(t *testing.T) {
|
|
testFileSystem(t, func(fs *FileSystem) {
|
|
api := fs.api
|
|
bzzhash, err := fs.Upload(path.Join(testDir, "test0"), "index.html")
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
return
|
|
}
|
|
|
|
content := readPath(t, testDir, "test0", "index.html")
|
|
resp := testGet(t, api, bzzhash)
|
|
exp := expResponse(content, "text/html; charset=utf-8", 0)
|
|
checkResponse(t, resp, exp)
|
|
})
|
|
}
|
|
|
|
func TestApiFileUpload(t *testing.T) {
|
|
testFileSystem(t, func(fs *FileSystem) {
|
|
api := fs.api
|
|
bzzhash, err := fs.Upload(path.Join(testDir, "test0", "index.html"), "")
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
return
|
|
}
|
|
|
|
content := readPath(t, testDir, "test0", "index.html")
|
|
resp := testGet(t, api, bzzhash+"/index.html")
|
|
exp := expResponse(content, "text/html; charset=utf-8", 0)
|
|
checkResponse(t, resp, exp)
|
|
})
|
|
}
|
|
|
|
func TestApiFileUploadWithRootFile(t *testing.T) {
|
|
testFileSystem(t, func(fs *FileSystem) {
|
|
api := fs.api
|
|
bzzhash, err := fs.Upload(path.Join(testDir, "test0", "index.html"), "index.html")
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
return
|
|
}
|
|
|
|
content := readPath(t, testDir, "test0", "index.html")
|
|
resp := testGet(t, api, bzzhash)
|
|
exp := expResponse(content, "text/html; charset=utf-8", 0)
|
|
checkResponse(t, resp, exp)
|
|
})
|
|
}
|