tokenmigrator.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. const jsonfile = require('jsonfile');
  2. const BigNumber = require('bignumber.js');
  3. const Migrator = artifacts.require("Migrator");
  4. const TokenImplementation = artifacts.require("TokenImplementation");
  5. contract("Migrator", function (accounts) {
  6. var migrator,
  7. fromToken,
  8. toToken,
  9. fromDecimals = 8,
  10. toDecimals = 18;
  11. it("should deploy with the correct values", async function () {
  12. fromToken = await TokenImplementation.new();
  13. await fromToken.initialize(
  14. "TestFrom",
  15. "FROM",
  16. fromDecimals,
  17. 0,
  18. accounts[0],
  19. 0,
  20. "0x00"
  21. )
  22. toToken = await TokenImplementation.new();
  23. await toToken.initialize(
  24. "TestTo",
  25. "TO",
  26. toDecimals,
  27. 0,
  28. accounts[0],
  29. 0,
  30. "0x00"
  31. )
  32. migrator = await Migrator.new(
  33. fromToken.address,
  34. toToken.address,
  35. );
  36. assert.equal(await migrator.fromAsset(), fromToken.address)
  37. assert.equal(await migrator.toAsset(), toToken.address)
  38. assert.equal((await migrator.fromDecimals()).toNumber(), fromDecimals)
  39. assert.equal((await migrator.toDecimals()).toNumber(), toDecimals)
  40. })
  41. it("should give out LP tokens 1:1 for a toToken deposit", async function () {
  42. await toToken.mint(accounts[0], "1000000000000000000")
  43. await toToken.approve(migrator.address, "1000000000000000000")
  44. await migrator.add("1000000000000000000")
  45. assert.equal((await toToken.balanceOf(migrator.address)).toString(), "1000000000000000000")
  46. assert.equal((await migrator.balanceOf(accounts[0])).toString(), "1000000000000000000")
  47. })
  48. it("should refund toToken for LP tokens", async function () {
  49. await migrator.remove("500000000000000000")
  50. assert.equal((await toToken.balanceOf(migrator.address)).toString(), "500000000000000000")
  51. assert.equal((await toToken.balanceOf(accounts[0])).toString(), "500000000000000000")
  52. assert.equal((await migrator.balanceOf(accounts[0])).toString(), "500000000000000000")
  53. })
  54. it("should redeem fromToken to toToken adjusting for decimals", async function () {
  55. await fromToken.mint(accounts[1], "50000000")
  56. await fromToken.approve(migrator.address, "50000000", {
  57. from : accounts[1]
  58. })
  59. await migrator.migrate("50000000", {
  60. from : accounts[1]
  61. })
  62. assert.equal((await toToken.balanceOf(accounts[1])).toString(), "500000000000000000")
  63. assert.equal((await fromToken.balanceOf(accounts[1])).toString(), "0")
  64. assert.equal((await fromToken.balanceOf(migrator.address)).toString(), "50000000")
  65. assert.equal((await toToken.balanceOf(migrator.address)).toString(), "0")
  66. })
  67. it("fromToken should be claimable for LP tokens, adjusting for decimals", async function () {
  68. await migrator.claim("500000000000000000")
  69. assert.equal((await fromToken.balanceOf(migrator.address)).toString(), "0")
  70. assert.equal((await fromToken.balanceOf(accounts[0])).toString(), "50000000")
  71. assert.equal((await migrator.balanceOf(accounts[0])).toString(), "0")
  72. })
  73. })