@@ -10,8 +10,18 @@ const {
10
10
const { assert, expect } = require ( "chai" ) ;
11
11
12
12
// Use "WormholeReceiver" if you are testing with Wormhole Receiver
13
+ const Setup = artifacts . require ( "Setup" ) ;
14
+ const Implementation = artifacts . require ( "Implementation" ) ;
13
15
const Wormhole = artifacts . require ( "Wormhole" ) ;
14
16
17
+ const ReceiverSetup = artifacts . require ( "ReceiverSetup" ) ;
18
+ const ReceiverImplementation = artifacts . require ( "ReceiverImplementation" ) ;
19
+ const WormholeReceiver = artifacts . require ( "WormholeReceiver" ) ;
20
+
21
+ const wormholeGovernanceChainId = governance . CHAINS . solana ;
22
+ const wormholeGovernanceContract =
23
+ "0x0000000000000000000000000000000000000000000000000000000000000004" ;
24
+
15
25
const PythUpgradable = artifacts . require ( "PythUpgradable" ) ;
16
26
const MockPythUpgrade = artifacts . require ( "MockPythUpgrade" ) ;
17
27
const MockUpgradeableProxy = artifacts . require ( "MockUpgradeableProxy" ) ;
@@ -1069,6 +1079,136 @@ contract("Pyth", function () {
1069
1079
// and adding it here will cause more complexity (and is not so short).
1070
1080
} ) ;
1071
1081
1082
+ it ( "Setting wormhole address should work" , async function ( ) {
1083
+ // Deploy a new wormhole contract
1084
+ const newSetup = await Setup . new ( ) ;
1085
+ const newImpl = await Implementation . new ( ) ;
1086
+
1087
+ // encode initialisation data
1088
+ const initData = newSetup . contract . methods
1089
+ . setup (
1090
+ newImpl . address ,
1091
+ [ testSigner1 . address ] ,
1092
+ governance . CHAINS . polygon , // changing the chain id to polygon
1093
+ wormholeGovernanceChainId ,
1094
+ wormholeGovernanceContract
1095
+ )
1096
+ . encodeABI ( ) ;
1097
+
1098
+ const newWormhole = await Wormhole . new ( newSetup . address , initData ) ;
1099
+
1100
+ // Creating the vaa to set the new wormhole address
1101
+ const data = new governance . EthereumSetWormholeAddress (
1102
+ governance . CHAINS . ethereum ,
1103
+ new governance . HexString20Bytes ( newWormhole . address )
1104
+ ) . serialize ( ) ;
1105
+
1106
+ const vaa = await createVAAFromUint8Array (
1107
+ data ,
1108
+ testGovernanceChainId ,
1109
+ testGovernanceEmitter ,
1110
+ 1
1111
+ ) ;
1112
+
1113
+ assert . equal ( await this . pythProxy . chainId ( ) , governance . CHAINS . ethereum ) ;
1114
+
1115
+ const oldWormholeAddress = await this . pythProxy . wormhole ( ) ;
1116
+
1117
+ const receipt = await this . pythProxy . executeGovernanceInstruction ( vaa ) ;
1118
+ expectEvent ( receipt , "WormholeAddressSet" , {
1119
+ oldWormholeAddress : oldWormholeAddress ,
1120
+ newWormholeAddress : newWormhole . address ,
1121
+ } ) ;
1122
+
1123
+ assert . equal ( await this . pythProxy . wormhole ( ) , newWormhole . address ) ;
1124
+ assert . equal ( await this . pythProxy . chainId ( ) , governance . CHAINS . polygon ) ;
1125
+ } ) ;
1126
+
1127
+ it ( "Setting wormhole address to WormholeReceiver should work" , async function ( ) {
1128
+ // Deploy a new wormhole receiver contract
1129
+ const newReceiverSetup = await ReceiverSetup . new ( ) ;
1130
+ const newReceiverImpl = await ReceiverImplementation . new ( ) ;
1131
+
1132
+ // encode initialisation data
1133
+ const initData = newReceiverSetup . contract . methods
1134
+ . setup (
1135
+ newReceiverImpl . address ,
1136
+ [ testSigner1 . address ] ,
1137
+ governance . CHAINS . polygon , // changing the chain id to polygon
1138
+ wormholeGovernanceChainId ,
1139
+ wormholeGovernanceContract
1140
+ )
1141
+ . encodeABI ( ) ;
1142
+
1143
+ const newWormholeReceiver = await WormholeReceiver . new (
1144
+ newReceiverSetup . address ,
1145
+ initData
1146
+ ) ;
1147
+
1148
+ // Creating the vaa to set the new wormhole address
1149
+ const data = new governance . EthereumSetWormholeAddress (
1150
+ governance . CHAINS . ethereum ,
1151
+ new governance . HexString20Bytes ( newWormholeReceiver . address )
1152
+ ) . serialize ( ) ;
1153
+
1154
+ const vaa = await createVAAFromUint8Array (
1155
+ data ,
1156
+ testGovernanceChainId ,
1157
+ testGovernanceEmitter ,
1158
+ 1
1159
+ ) ;
1160
+
1161
+ assert . equal ( await this . pythProxy . chainId ( ) , governance . CHAINS . ethereum ) ;
1162
+
1163
+ const oldWormholeAddress = await this . pythProxy . wormhole ( ) ;
1164
+
1165
+ const receipt = await this . pythProxy . executeGovernanceInstruction ( vaa ) ;
1166
+ expectEvent ( receipt , "WormholeAddressSet" , {
1167
+ oldWormholeAddress : oldWormholeAddress ,
1168
+ newWormholeAddress : newWormholeReceiver . address ,
1169
+ } ) ;
1170
+
1171
+ assert . equal ( await this . pythProxy . wormhole ( ) , newWormholeReceiver . address ) ;
1172
+ assert . equal ( await this . pythProxy . chainId ( ) , governance . CHAINS . polygon ) ;
1173
+ } ) ;
1174
+
1175
+ it ( "Setting wormhole address to a wrong contract should reject" , async function ( ) {
1176
+ // Deploy a new wormhole contract
1177
+ const newSetup = await Setup . new ( ) ;
1178
+ const newImpl = await Implementation . new ( ) ;
1179
+
1180
+ // encode initialisation data
1181
+ const initData = newSetup . contract . methods
1182
+ . setup (
1183
+ newImpl . address ,
1184
+ [ testSigner2 . address ] , // A wrong signer
1185
+ governance . CHAINS . ethereum ,
1186
+ wormholeGovernanceChainId ,
1187
+ wormholeGovernanceContract
1188
+ )
1189
+ . encodeABI ( ) ;
1190
+
1191
+ const newWormhole = await Wormhole . new ( newSetup . address , initData ) ;
1192
+
1193
+ // Creating the vaa to set the new wormhole address
1194
+ const data = new governance . EthereumSetWormholeAddress (
1195
+ governance . CHAINS . ethereum ,
1196
+ new governance . HexString20Bytes ( newWormhole . address )
1197
+ ) . serialize ( ) ;
1198
+
1199
+ const wrongVaa = await createVAAFromUint8Array (
1200
+ data ,
1201
+ testGovernanceChainId ,
1202
+ testGovernanceEmitter ,
1203
+ 1
1204
+ ) ;
1205
+
1206
+ await expectRevertCustomError (
1207
+ this . pythProxy . executeGovernanceInstruction ( wrongVaa ) ,
1208
+ "InvalidGovernanceMessage"
1209
+ ) ;
1210
+ } ) ;
1211
+
1072
1212
// Version
1073
1213
1074
1214
it ( "Make sure version is the npm package version" , async function ( ) {
0 commit comments