Skip to content

Commit cee7e9b

Browse files
lhaskinsmastersingh24
authored andcommitted
[FAB-10255] Consolidate the chaincode for tests
Instead of each test setup having it's own copy of chaincode we should have a single chaincodei directory containing chaincode that can be accessed. Change-Id: I93916f9875f9d8d302d7a42f2488536050614bfb Signed-off-by: Latitia M. Haskins <latitia.haskins@gmail.com>
1 parent 36eca57 commit cee7e9b

File tree

13 files changed

+28
-736
lines changed

13 files changed

+28
-736
lines changed

integration/e2e/testdata/chaincode/src/simple/cmd/main.go integration/chaincode/simple/cmd/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import (
1010
"fmt"
1111
"os"
1212

13-
"simple"
14-
1513
"github.com/hyperledger/fabric/core/chaincode/shim"
14+
"github.com/hyperledger/fabric/integration/chaincode/simple"
1615
)
1716

1817
func main() {

integration/e2e/e2e_test.go

+3-28
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"io/ioutil"
1212
"os"
1313
"path/filepath"
14-
"strings"
1514
"syscall"
1615
"time"
1716

@@ -93,8 +92,7 @@ var _ = Describe("EndToEnd", func() {
9392
Chaincode: world.Chaincode{
9493
Name: "mycc",
9594
Version: "1.0",
96-
Path: filepath.Join("simple", "cmd"),
97-
GoPath: filepath.Join(testDir, "chaincode"),
95+
Path: "github.com/hyperledger/fabric/integration/chaincode/simple/cmd",
9896
ExecPath: os.Getenv("PATH"),
9997
},
10098
InitArgs: `{"Args":["init","a","100","b","200"]}`,
@@ -237,38 +235,15 @@ var _ = Describe("EndToEnd", func() {
237235
w.BuildNetwork()
238236

239237
By("setting up the channel")
240-
copyDir(filepath.Join("testdata", "chaincode"), filepath.Join(testDir, "chaincode"))
241238
err := w.SetupChannel()
242239
Expect(err).NotTo(HaveOccurred())
243240

244-
By("verifying the chaincode is installed")
245-
adminPeer := components.Peer()
246-
adminPeer.ConfigDir = filepath.Join(testDir, "org1.example.com_0")
247-
adminPeer.MSPConfigPath = filepath.Join(testDir, "crypto", "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
248-
adminRunner := adminPeer.ChaincodeListInstalled()
249-
execute(adminRunner)
250-
Eventually(adminRunner.Buffer()).Should(gbytes.Say("Path: simple/cmd"))
251-
252-
By("waiting for the chaincode to complete instantiation")
253-
listInstantiated := func() bool {
254-
p := components.Peer()
255-
p.ConfigDir = filepath.Join(testDir, "org1.example.com_0")
256-
p.MSPConfigPath = filepath.Join(testDir, "crypto", "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
257-
adminRunner := p.ChaincodeListInstantiated(w.Deployment.Channel)
258-
err := execute(adminRunner)
259-
if err != nil {
260-
return false
261-
}
262-
return strings.Contains(string(adminRunner.Buffer().Contents()), "Path: simple/cmd")
263-
}
264-
Eventually(listInstantiated, 30*time.Second, 500*time.Millisecond).Should(BeTrue())
265-
266241
By("querying the chaincode")
267-
adminPeer = components.Peer()
242+
adminPeer := components.Peer()
268243
adminPeer.LogLevel = "debug"
269244
adminPeer.ConfigDir = filepath.Join(testDir, "org1.example.com_0")
270245
adminPeer.MSPConfigPath = filepath.Join(testDir, "crypto", "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
271-
adminRunner = adminPeer.QueryChaincode(w.Deployment.Chaincode.Name, w.Deployment.Channel, `{"Args":["query","a"]}`)
246+
adminRunner := adminPeer.QueryChaincode(w.Deployment.Chaincode.Name, w.Deployment.Channel, `{"Args":["query","a"]}`)
272247
execute(adminRunner)
273248
Eventually(adminRunner.Buffer()).Should(gbytes.Say("100"))
274249

integration/pluggable/e2e_test.go

+3-43
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"os"
1313
"os/exec"
1414
"path/filepath"
15-
"strings"
1615
"syscall"
1716
"time"
1817

@@ -93,8 +92,7 @@ var _ = Describe("EndToEnd", func() {
9392
Chaincode: world.Chaincode{
9493
Name: "mycc",
9594
Version: "1.0",
96-
Path: filepath.Join("simple", "cmd"),
97-
GoPath: filepath.Join(testDir, "chaincode"),
95+
Path: "github.com/hyperledger/fabric/integration/chaincode/simple/cmd",
9896
ExecPath: os.Getenv("PATH"),
9997
},
10098
InitArgs: `{"Args":["init","a","100","b","200"]}`,
@@ -237,7 +235,6 @@ var _ = Describe("EndToEnd", func() {
237235
w.BuildNetwork()
238236

239237
By("setting up the channel")
240-
copyDir(filepath.Join("testdata", "chaincode"), filepath.Join(testDir, "chaincode"))
241238
err := w.SetupChannel()
242239
Expect(err).NotTo(HaveOccurred())
243240

@@ -252,34 +249,12 @@ var _ = Describe("EndToEnd", func() {
252249
activations = CountValidationPluginActivations()
253250
Expect(activations).To(Equal(peerCount))
254251

255-
By("verifying the chaincode is installed")
256-
adminPeer := components.Peer()
257-
adminPeer.ConfigDir = filepath.Join(testDir, "org1.example.com_0")
258-
adminPeer.MSPConfigPath = filepath.Join(testDir, "crypto", "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
259-
adminRunner := adminPeer.ChaincodeListInstalled()
260-
execute(adminRunner)
261-
Eventually(adminRunner.Buffer()).Should(gbytes.Say("Path: simple/cmd"))
262-
263-
By("waiting for the chaincode to complete instantiation")
264-
listInstantiated := func() bool {
265-
p := components.Peer()
266-
p.ConfigDir = filepath.Join(testDir, "org1.example.com_0")
267-
p.MSPConfigPath = filepath.Join(testDir, "crypto", "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
268-
adminRunner := p.ChaincodeListInstantiated(w.Deployment.Channel)
269-
err := execute(adminRunner)
270-
if err != nil {
271-
return false
272-
}
273-
return strings.Contains(string(adminRunner.Buffer().Contents()), "Path: simple/cmd")
274-
}
275-
Eventually(listInstantiated, 30*time.Second, 500*time.Millisecond).Should(BeTrue())
276-
277252
By("querying the chaincode")
278-
adminPeer = components.Peer()
253+
adminPeer := components.Peer()
279254
adminPeer.LogLevel = "debug"
280255
adminPeer.ConfigDir = filepath.Join(testDir, "org1.example.com_0")
281256
adminPeer.MSPConfigPath = filepath.Join(testDir, "crypto", "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
282-
adminRunner = adminPeer.QueryChaincode(w.Deployment.Chaincode.Name, w.Deployment.Channel, `{"Args":["query","a"]}`)
257+
adminRunner := adminPeer.QueryChaincode(w.Deployment.Chaincode.Name, w.Deployment.Channel, `{"Args":["query","a"]}`)
283258
execute(adminRunner)
284259
Eventually(adminRunner.Buffer()).Should(gbytes.Say("100"))
285260

@@ -310,21 +285,6 @@ func copyFile(src, dest string) {
310285
Expect(err).NotTo(HaveOccurred())
311286
}
312287

313-
func copyDir(src, dest string) {
314-
os.MkdirAll(dest, 0755)
315-
objects, err := ioutil.ReadDir(src)
316-
for _, obj := range objects {
317-
srcfileptr := src + "/" + obj.Name()
318-
destfileptr := dest + "/" + obj.Name()
319-
if obj.IsDir() {
320-
copyDir(srcfileptr, destfileptr)
321-
} else {
322-
copyFile(srcfileptr, destfileptr)
323-
}
324-
}
325-
Expect(err).NotTo(HaveOccurred())
326-
}
327-
328288
func execute(r ifrit.Runner) (err error) {
329289
p := ifrit.Invoke(r)
330290
Eventually(p.Ready()).Should(BeClosed())

integration/pluggable/testdata/chaincode/src/simple/chaincode.go

-177
This file was deleted.

integration/pluggable/testdata/chaincode/src/simple/cmd/main.go

-24
This file was deleted.

0 commit comments

Comments
 (0)