-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow deploying Java chaincode from remote git repo
Currently only local deployment of Java chaincode is supported. Change-Id: Ib22ec81e7d1df137ee5ecd0f92353efdcad78d25 Signed-off-by: Satheesh Kathamuthu <satheesh.ceg@gmail.com>
- Loading branch information
1 parent
2570f8f
commit 80140c9
Showing
5 changed files
with
222 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
Copyright IBM Corp. 2016 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package java | ||
|
||
import ( | ||
"testing" | ||
|
||
"encoding/hex" | ||
|
||
"github.com/hyperledger/fabric/core/util" | ||
|
||
"bytes" | ||
"os" | ||
) | ||
|
||
func TestHashDiffRemoteRepo(t *testing.T) { | ||
b := []byte("firstcontent") | ||
hash := util.ComputeCryptoHash(b) | ||
|
||
srcPath1, err := getCodeFromHTTP("https://github.com/hyperledger/fabric-test-resources/") | ||
if err != nil { | ||
t.Logf("Error getting code from remote repo %s", err) | ||
t.Fail() | ||
} | ||
srcPath2, err := getCodeFromHTTP("https://github.com/hyperledger/fabric-sdk-java") | ||
if err != nil { | ||
t.Logf("Error getting code from remote repo %s", err) | ||
t.Fail() | ||
} | ||
|
||
defer func() { | ||
os.RemoveAll(srcPath1) | ||
}() | ||
defer func() { | ||
os.RemoveAll(srcPath2) | ||
}() | ||
hash1, err := hashFilesInDir(srcPath1, srcPath1, hash, nil) | ||
if err != nil { | ||
t.Logf("Error getting code %s", err) | ||
t.Fail() | ||
} | ||
hash2, err := hashFilesInDir(srcPath2, srcPath2, hash, nil) | ||
if err != nil { | ||
t.Logf("Error getting code %s", err) | ||
t.Fail() | ||
} | ||
if bytes.Compare(hash1, hash2) == 0 { | ||
t.Logf("Hash should be different for 2 different remote repos") | ||
t.Fail() | ||
} | ||
|
||
} | ||
func TestHashSameRemoteRepo(t *testing.T) { | ||
b := []byte("firstcontent") | ||
hash := util.ComputeCryptoHash(b) | ||
|
||
srcPath1, err := getCodeFromHTTP("https://github.com/hyperledger/fabric-test-resources") | ||
if err != nil { | ||
t.Logf("Error getting code from remote repo %s", err) | ||
t.Fail() | ||
} | ||
srcPath2, err := getCodeFromHTTP("https://github.com/hyperledger/fabric-test-resources") | ||
|
||
if err != nil { | ||
t.Logf("Error getting code from remote repo %s", err) | ||
t.Fail() | ||
} | ||
|
||
defer func() { | ||
os.RemoveAll(srcPath1) | ||
}() | ||
defer func() { | ||
os.RemoveAll(srcPath2) | ||
}() | ||
hash1, err := hashFilesInDir(srcPath1, srcPath1, hash, nil) | ||
if err != nil { | ||
t.Logf("Error getting code %s", err) | ||
t.Fail() | ||
} | ||
hash2, err := hashFilesInDir(srcPath2, srcPath2, hash, nil) | ||
if err != nil { | ||
t.Logf("Error getting code %s", err) | ||
t.Fail() | ||
} | ||
if bytes.Compare(hash1, hash2) != 0 { | ||
t.Logf("Hash should be same across multiple downloads") | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestHashOverLocalDir(t *testing.T) { | ||
b := []byte("firstcontent") | ||
hash := util.ComputeCryptoHash(b) | ||
|
||
hash, err := hashFilesInDir(".", "../golang/hashtestfiles", hash, nil) | ||
|
||
if err != nil { | ||
t.Fail() | ||
t.Logf("error : %s", err) | ||
} | ||
|
||
expectedHash := "7b3b2193bed2bd7c19300aa5d6d7f6bb4d61602e4978a78bc08028379cb5cf0ed877bd9db3e990230e8bf6c974edd765f3027f061fd8657d30fc858a676a6f4a" | ||
|
||
computedHash := hex.EncodeToString(hash[:]) | ||
|
||
if expectedHash != computedHash { | ||
t.Fail() | ||
t.Logf("Hash expected to be unchanged") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters