@@ -1752,13 +1752,12 @@ func TestValidateRWSetAndCollectionForDeploy(t *testing.T) {
1752
1752
// Test 1: More than two entries in the rwset -> error
1753
1753
rwset := & kvrwset.KVRWSet {Writes : []* kvrwset.KVWrite {{Key : ccid }, {Key : "b" }, {Key : "c" }}}
1754
1754
err = v .validateRWSetAndCollection (rwset , cdRWSet , nil , lsccFunc , ac , chid )
1755
- assert .Errorf (t , err , "LSCC can only issue one or two putState upon deploy" )
1755
+ assert .EqualError (t , err , "LSCC can only issue one or two putState upon deploy" )
1756
1756
1757
1757
// Test 2: Invalid key for the collection config package -> error
1758
1758
rwset = & kvrwset.KVRWSet {Writes : []* kvrwset.KVWrite {{Key : ccid }, {Key : "b" }}}
1759
1759
err = v .validateRWSetAndCollection (rwset , cdRWSet , nil , lsccFunc , ac , chid )
1760
- assert .Errorf (t , err , "invalid key for the collection of chaincode %s:%s; expected '%s', received '%s'" ,
1761
- cdRWSet .Name , cdRWSet .Version , privdata .BuildCollectionKVSKey (rwset .Writes [1 ].Key ), rwset .Writes [1 ].Key )
1760
+ assert .EqualError (t , err , "invalid key for the collection of chaincode mycc:1.0; expected 'mycc~collection', received 'b'" )
1762
1761
1763
1762
// Test 3: No collection config package -> success
1764
1763
rwset = & kvrwset.KVRWSet {Writes : []* kvrwset.KVWrite {{Key : ccid }}}
@@ -1774,15 +1773,15 @@ func TestValidateRWSetAndCollectionForDeploy(t *testing.T) {
1774
1773
err = v .validateRWSetAndCollection (rwset , cdRWSet , lsccargs , lsccFunc , ac , chid )
1775
1774
assert .NoError (t , err )
1776
1775
1777
- // Test 5: Invalid collection config package -> error
1776
+ // Test 5: Collection configuration of the lscc args doesn't match the rwset
1778
1777
lsccargs = [][]byte {nil , nil , nil , nil , nil , []byte ("barf" )}
1779
1778
err = v .validateRWSetAndCollection (rwset , cdRWSet , lsccargs , lsccFunc , ac , chid )
1780
- assert .Errorf (t , err , "invalid collection configuration supplied for chaincode %s:%s" , cdRWSet . Name , cdRWSet . Version )
1779
+ assert .EqualError (t , err , "collection configuration arguments supplied for chaincode mycc:1.0 do not match the configuration in the lscc writeset" )
1781
1780
1782
1781
// Test 6: Invalid collection config package -> error
1783
1782
rwset = & kvrwset.KVRWSet {Writes : []* kvrwset.KVWrite {{Key : ccid }, {Key : privdata .BuildCollectionKVSKey ("mycc" ), Value : []byte ("barf" )}}}
1784
1783
err = v .validateRWSetAndCollection (rwset , cdRWSet , lsccargs , lsccFunc , ac , chid )
1785
- assert .Errorf (t , err , "invalid collection configuration supplied for chaincode %s:%s" , cdRWSet . Name , cdRWSet . Version )
1784
+ assert .EqualError (t , err , "invalid collection configuration supplied for chaincode mycc:1.0" )
1786
1785
1787
1786
// Test 7: Valid collection config package -> success
1788
1787
collName1 := "mycollection1"
@@ -1820,16 +1819,24 @@ func TestValidateRWSetAndCollectionForDeploy(t *testing.T) {
1820
1819
1821
1820
// Test 10: Duplicate collections in the collection config package -> error
1822
1821
err = testValidateCollection (t , v , []* common.CollectionConfig {coll1 , coll2 , coll1 }, cdRWSet , lsccFunc , ac , chid )
1823
- assert .Errorf (t , err , "collection-name: %s -- found duplicate collection configuration" , collName1 )
1822
+ assert .EqualError (t , err , "collection-name: mycollection1 -- found duplicate collection configuration" )
1823
+
1824
+ // Test 11: requiredPeerCount < 0 -> error
1825
+ requiredPeerCount = - 2
1826
+ maximumPeerCount = 1
1827
+ blockToLive = 10000
1828
+ coll3 = createCollectionConfig (collName3 , policyEnvelope , requiredPeerCount , maximumPeerCount , blockToLive )
1829
+ err = testValidateCollection (t , v , []* common.CollectionConfig {coll1 , coll2 , coll3 }, cdRWSet , lsccFunc , ac , chid )
1830
+ assert .EqualError (t , err , "collection-name: mycollection3 -- requiredPeerCount (1) cannot be less than zero (-2)" ,
1831
+ collName3 , maximumPeerCount , requiredPeerCount )
1824
1832
1825
1833
// Test 11: requiredPeerCount > maximumPeerCount -> error
1826
1834
requiredPeerCount = 2
1827
1835
maximumPeerCount = 1
1828
1836
blockToLive = 10000
1829
1837
coll3 = createCollectionConfig (collName3 , policyEnvelope , requiredPeerCount , maximumPeerCount , blockToLive )
1830
1838
err = testValidateCollection (t , v , []* common.CollectionConfig {coll1 , coll2 , coll3 }, cdRWSet , lsccFunc , ac , chid )
1831
- assert .Errorf (t , err , "collection-name: %s -- maximum peer count (%d) cannot be greater than the required peer count (%d)" ,
1832
- collName3 , maximumPeerCount , requiredPeerCount )
1839
+ assert .EqualError (t , err , "collection-name: mycollection3 -- maximum peer count (1) cannot be greater than the required peer count (2)" )
1833
1840
1834
1841
// Test 12: AND concatenation of orgs in access policy -> error
1835
1842
requiredPeerCount = 1
@@ -1838,6 +1845,14 @@ func TestValidateRWSetAndCollectionForDeploy(t *testing.T) {
1838
1845
coll3 = createCollectionConfig (collName3 , policyEnvelope , requiredPeerCount , maximumPeerCount , blockToLive )
1839
1846
err = testValidateCollection (t , v , []* common.CollectionConfig {coll3 }, cdRWSet , lsccFunc , ac , chid )
1840
1847
assert .EqualError (t , err , "collection-name: mycollection3 -- error in member org policy: signature policy is not an OR concatenation, NOutOf 2" )
1848
+
1849
+ // Test 13: deploy with existing collection config on the ledger -> error
1850
+ ccp := & common.CollectionConfigPackage {[]* common.CollectionConfig {coll1 }}
1851
+ ccpBytes , err := proto .Marshal (ccp )
1852
+ assert .NoError (t , err )
1853
+ state ["lscc" ][privdata .BuildCollectionKVSKey (ccid )] = ccpBytes
1854
+ err = testValidateCollection (t , v , []* common.CollectionConfig {coll1 }, cdRWSet , lsccFunc , ac , chid )
1855
+ assert .EqualError (t , err , "collection data should not exist for chaincode mycc:1.0" )
1841
1856
}
1842
1857
1843
1858
func TestValidateRWSetAndCollectionForUpgrade (t * testing.T ) {
@@ -1887,12 +1902,11 @@ func TestValidateRWSetAndCollectionForUpgrade(t *testing.T) {
1887
1902
1888
1903
// Test 3: missing one existing collection (check based on the length) -> error
1889
1904
err = testValidateCollection (t , v , []* common.CollectionConfig {coll1 }, cdRWSet , lsccFunc , ac , chid )
1890
- assert .Errorf (t , err , "Some existing collection configurations are missing in the new collection configuration package" )
1905
+ assert .EqualError (t , err , "Some existing collection configurations are missing in the new collection configuration package" )
1891
1906
1892
1907
// Test 4: missing one existing collection (check based on the collection names) -> error
1893
1908
err = testValidateCollection (t , v , []* common.CollectionConfig {coll1 , coll3 }, cdRWSet , lsccFunc , ac , chid )
1894
- assert .Errorf (t , err , "existing collection named %s is missing in the new collection configuration package" ,
1895
- collName2 )
1909
+ assert .EqualError (t , err , "existing collection named mycollection2 is missing in the new collection configuration package" )
1896
1910
1897
1911
// Test 5: adding a new collection along with the existing collections -> success
1898
1912
err = testValidateCollection (t , v , []* common.CollectionConfig {coll1 , coll2 , coll3 }, cdRWSet , lsccFunc , ac , chid )
@@ -1903,7 +1917,7 @@ func TestValidateRWSetAndCollectionForUpgrade(t *testing.T) {
1903
1917
1904
1918
// Test 6: modify the BlockToLive in an existing collection -> error
1905
1919
err = testValidateCollection (t , v , []* common.CollectionConfig {coll1 , coll2 , coll3 }, cdRWSet , lsccFunc , ac , chid )
1906
- assert .Errorf (t , err , "BlockToLive in the existing collection named %s cannot be changed" , collName2 )
1920
+ assert .EqualError (t , err , "BlockToLive in the existing collection named mycollection2 cannot be changed" )
1907
1921
}
1908
1922
1909
1923
var lccctestpath = "/tmp/lscc-validation-test"
0 commit comments