@@ -91,7 +91,7 @@ describe("verify task integration tests", () => {
91
91
} ) ;
92
92
93
93
expect ( logStub ) . to . be . calledOnceWith (
94
- `The contract ${ address } has already been verified on Etherscan .
94
+ `The contract ${ address } has already been verified on the block explorer. If you're trying to verify a partially verified contract, please use the --force flag .
95
95
https://hardhat.etherscan.io/address/${ address } #code`
96
96
) ;
97
97
logStub . restore ( ) ;
@@ -629,6 +629,132 @@ https://hardhat.etherscan.io/address/${bothLibsContractAddress}#code\n`);
629
629
await this . hre . run ( TASK_CLEAN ) ;
630
630
} ) ;
631
631
} ) ;
632
+
633
+ describe ( "with a verified contract and '--force' flag" , ( ) => {
634
+ let simpleContractAddress : string ;
635
+ before ( async function ( ) {
636
+ await this . hre . run ( TASK_COMPILE , { force : true , quiet : true } ) ;
637
+ simpleContractAddress = await deployContract (
638
+ "SimpleContract" ,
639
+ [ ] ,
640
+ this . hre
641
+ ) ;
642
+ } ) ;
643
+
644
+ beforeEach ( ( ) => {
645
+ interceptIsVerified ( { message : "OK" , result : [ { SourceCode : "code" } ] } ) ;
646
+ } ) ;
647
+
648
+ it ( "should validate a partially verified contract" , async function ( ) {
649
+ interceptVerify ( {
650
+ status : 1 ,
651
+ result : "ezq878u486pzijkvvmerl6a9mzwhv6sefgvqi5tkwceejc7tvn" ,
652
+ } ) ;
653
+ interceptGetStatus ( ( ) => {
654
+ return {
655
+ status : 1 ,
656
+ result : "Pass - Verified" ,
657
+ } ;
658
+ } ) ;
659
+ const logStub = sinon . stub ( console , "log" ) ;
660
+
661
+ const taskResponse = await this . hre . run ( TASK_VERIFY , {
662
+ address : simpleContractAddress ,
663
+ constructorArgsParams : [ ] ,
664
+ force : true ,
665
+ } ) ;
666
+
667
+ assert . equal ( logStub . callCount , 2 ) ;
668
+ expect ( logStub . getCall ( 0 ) ) . to . be
669
+ . calledWith ( `Successfully submitted source code for contract
670
+ contracts/SimpleContract.sol:SimpleContract at ${ simpleContractAddress }
671
+ for verification on the block explorer. Waiting for verification result...
672
+ ` ) ;
673
+ expect ( logStub . getCall ( 1 ) ) . to . be
674
+ . calledWith ( `Successfully verified contract SimpleContract on the block explorer.
675
+ https://hardhat.etherscan.io/address/${ simpleContractAddress } #code\n` ) ;
676
+ logStub . restore ( ) ;
677
+ assert . isUndefined ( taskResponse ) ;
678
+ } ) ;
679
+
680
+ it ( "should throw if the verification response status is 'already verified' (blockscout full matched)" , async function ( ) {
681
+ interceptVerify ( {
682
+ status : 0 ,
683
+ result : "Smart-contract already verified." ,
684
+ } ) ;
685
+
686
+ await expect (
687
+ this . hre . run ( TASK_VERIFY_ETHERSCAN , {
688
+ address : simpleContractAddress ,
689
+ constructorArgsParams : [ ] ,
690
+ force : true ,
691
+ } )
692
+ ) . to . be . rejectedWith (
693
+ new RegExp (
694
+ `The block explorer's API responded that the contract contracts/SimpleContract.sol:SimpleContract at ${ simpleContractAddress } is already verified.`
695
+ )
696
+ ) ;
697
+ } ) ;
698
+
699
+ // If contract was actually verified, Etherscan returns an error on the verification request.
700
+ it ( "should throw if the verification response status is 'already verified' (etherscan manually verified)" , async function ( ) {
701
+ interceptVerify ( {
702
+ status : 0 ,
703
+ result : "Contract source code already verified" ,
704
+ } ) ;
705
+
706
+ await expect (
707
+ this . hre . run ( TASK_VERIFY_ETHERSCAN , {
708
+ address : simpleContractAddress ,
709
+ constructorArgsParams : [ ] ,
710
+ force : true ,
711
+ } )
712
+ ) . to . be . rejectedWith (
713
+ new RegExp (
714
+ `The block explorer's API responded that the contract contracts/SimpleContract.sol:SimpleContract at ${ simpleContractAddress } is already verified.`
715
+ )
716
+ ) ;
717
+ } ) ;
718
+
719
+ // If contract was verified via matching a deployed bytecode of another contract,
720
+ // Etherscan returns an error only on ve get verification status response.
721
+ it ( "should throw if the get verification status is 'already verified' (etherscan automatically verified)" , async function ( ) {
722
+ interceptVerify ( {
723
+ status : 1 ,
724
+ result : "ezq878u486pzijkvvmerl6a9mzwhv6sefgvqi5tkwceejc7tvn" ,
725
+ } ) ;
726
+ interceptGetStatus ( ( ) => {
727
+ return {
728
+ status : 0 ,
729
+ result : "Already Verified" ,
730
+ } ;
731
+ } ) ;
732
+ const logStub = sinon . stub ( console , "log" ) ;
733
+
734
+ await expect (
735
+ this . hre . run ( TASK_VERIFY_ETHERSCAN , {
736
+ address : simpleContractAddress ,
737
+ constructorArgsParams : [ ] ,
738
+ force : true ,
739
+ } )
740
+ ) . to . be . rejectedWith (
741
+ new RegExp (
742
+ `The block explorer's API responded that the contract contracts/SimpleContract.sol:SimpleContract at ${ simpleContractAddress } is already verified.`
743
+ )
744
+ ) ;
745
+
746
+ expect ( logStub ) . to . be
747
+ . calledOnceWith ( `Successfully submitted source code for contract
748
+ contracts/SimpleContract.sol:SimpleContract at ${ simpleContractAddress }
749
+ for verification on the block explorer. Waiting for verification result...
750
+ ` ) ;
751
+ logStub . restore ( ) ;
752
+ } ) ;
753
+
754
+ after ( async function ( ) {
755
+ await this . hre . run ( TASK_CLEAN ) ;
756
+ } ) ;
757
+ } ) ;
632
758
} ) ;
633
759
634
760
describe ( "verify task Sourcify's integration tests" , ( ) => {
0 commit comments