@@ -37,4 +37,68 @@ export async function copyWormholeV2Artifact(
3737 path . join ( targetArtifactDir , file )
3838 )
3939 }
40+
41+ // Merge the V2 contract's OpenZeppelin upgrade validation data from the
42+ // solidity package into this package's cache. The OZ upgrades plugin
43+ // populates validations.json only for locally-compiled contracts. Since
44+ // the V2 artifact is copied (not compiled here), its validation entry
45+ // must be merged so that prepareUpgrade() can resolve the contract.
46+ await mergeV2ValidationData ( hre , packageDir , contractName )
47+ }
48+
49+ async function mergeV2ValidationData (
50+ hre : HardhatRuntimeEnvironment ,
51+ packageDir : string ,
52+ contractName : string
53+ ) : Promise < void > {
54+ const sourceCachePath = path . resolve (
55+ packageDir ,
56+ "../../solidity/cache/validations.json"
57+ )
58+ const targetCachePath = path . resolve ( hre . config . paths . cache , "validations.json" )
59+
60+ let sourceData : any
61+ try {
62+ sourceData = JSON . parse (
63+ await fs . promises . readFile ( sourceCachePath , "utf8" )
64+ )
65+ } catch {
66+ // Solidity package validation cache not available; skip silently.
67+ return
68+ }
69+
70+ let targetData : any
71+ try {
72+ targetData = JSON . parse (
73+ await fs . promises . readFile ( targetCachePath , "utf8" )
74+ )
75+ } catch {
76+ // Local validation cache not available; skip silently.
77+ return
78+ }
79+
80+ // Find the log entry containing the V2 contract in the source cache
81+ const sourceLog : any [ ] = sourceData . log || [ ]
82+ const sourceEntry = sourceLog . find ( ( entry : any ) =>
83+ Object . keys ( entry ) . some ( ( key ) => key . includes ( contractName ) )
84+ )
85+
86+ if ( ! sourceEntry ) return
87+
88+ // Check whether the V2 contract is already present in the target cache
89+ const targetLog : any [ ] = targetData . log || [ ]
90+ const alreadyPresent = targetLog . some ( ( entry : any ) =>
91+ Object . keys ( entry ) . some ( ( key ) => key . includes ( contractName ) )
92+ )
93+
94+ if ( alreadyPresent ) return
95+
96+ // Append the source entry to the target validation log
97+ targetLog . push ( sourceEntry )
98+ targetData . log = targetLog
99+
100+ await fs . promises . writeFile (
101+ targetCachePath ,
102+ JSON . stringify ( targetData , null , 2 )
103+ )
40104}
0 commit comments