test.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // This test is intended to be run on devnet without an active eth miner
  2. // see https://github.com/trufflesuite/ganache-cli-archive#custom-methods
  3. const {
  4. NodeHttpTransport,
  5. } = require("@improbable-eng/grpc-web-node-http-transport");
  6. const { ethers } = require("ethers");
  7. const { parseUnits } = require("ethers/lib/utils");
  8. const {
  9. approveEth,
  10. transferFromEth,
  11. CHAIN_ID_BSC,
  12. CHAIN_ID_ETH,
  13. hexToUint8Array,
  14. nativeToHexString,
  15. parseSequenceFromLogEth,
  16. getEmitterAddressEth,
  17. getSignedVAA,
  18. BridgeImplementation__factory,
  19. } = require("@certusone/wormhole-sdk");
  20. const BSC_NODE_URL = "ws://localhost:8546";
  21. const ETH_NODE_URL = "ws://localhost:8545";
  22. const ETH_PRIVATE_KEY =
  23. "0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d";
  24. const ETH_TOKEN_BRIDGE_ADDRESS = "0x0290FB167208Af455bB137780163b7B7a9a10C16";
  25. // see https://eips.ethereum.org/EIPS/eip-1967#logic-contract-address
  26. const LOGIC_CONTRACT_STORAGE =
  27. "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc";
  28. const SIGNED_VAA =
  29. "010000000001003fd2219eed5b1a433120cf3edc37ab6c28f86222aa552e294e175e7e42ff32301c5c936b16ae6470bdfedbe9d7cdb50e664aac1e19da8489a7369caa7e1b5439010000000100000001000100000000000000000000000000000000000000000000000000000000000000040000000002a0518100000000000000000000000000000000000000000000546f6b656e427269646765020002000000000000000000000000daa71fbba28c946258dd3d5fcc9001401f72270f";
  30. (async () => {
  31. // create a signer for Eth
  32. const provider = new ethers.providers.WebSocketProvider(ETH_NODE_URL);
  33. const signer = new ethers.Wallet(ETH_PRIVATE_KEY, provider);
  34. const tokenBridge = BridgeImplementation__factory.connect(
  35. ETH_TOKEN_BRIDGE_ADDRESS,
  36. signer
  37. );
  38. console.log(
  39. "OLD IMPL",
  40. await provider.getStorageAt(
  41. ETH_TOKEN_BRIDGE_ADDRESS,
  42. LOGIC_CONTRACT_STORAGE
  43. )
  44. );
  45. console.log("OLD WETH", await tokenBridge.WETH());
  46. console.log("UPGRADING...");
  47. await tokenBridge.upgrade("0x" + SIGNED_VAA);
  48. console.log("SUCCESS!");
  49. console.log(
  50. "NEW IMPL",
  51. await provider.getStorageAt(
  52. ETH_TOKEN_BRIDGE_ADDRESS,
  53. LOGIC_CONTRACT_STORAGE
  54. )
  55. );
  56. console.log("NEW WETH", await tokenBridge.WETH());
  57. provider.destroy();
  58. })();