NFTServiceTest.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package com.izouma.nineth.service;
  2. import com.izouma.nineth.ApplicationTests;
  3. import org.apache.commons.lang3.RandomStringUtils;
  4. import org.junit.Test;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import java.io.File;
  7. import java.util.Scanner;
  8. public class NFTServiceTest extends ApplicationTests {
  9. @Autowired
  10. private NFTService nftService;
  11. @Test
  12. public void createAccount() {
  13. nftService.createAccount(RandomStringUtils.randomAlphabetic(8));
  14. }
  15. @Test
  16. public void createToken() throws Exception {
  17. for (int i = 0; i < 100; i++) {
  18. nftService.createToken("nine-space-official");
  19. }
  20. }
  21. @Test
  22. public void testCreateToken() {
  23. }
  24. @Test
  25. public void transferToken() throws Exception {
  26. nftService.transferToken("000000000000000000000000000000000000000000000000000000000000009d",
  27. "9th_BHlKkGWw", "9th_test");
  28. }
  29. @Test
  30. public void setApprovalForAll() throws Exception {
  31. nftService.setApprovalForAll("9th_test");
  32. }
  33. @Test
  34. public void deployContract() throws Exception {
  35. ProcessBuilder builder = new ProcessBuilder("/Users/drew/Projects/Java/9th/src/main/contract/mychain_solc", "--bin", "9th.sol");
  36. builder.directory(new File("/Users/drew/Projects/Java/9th/src/main/contract").getAbsoluteFile());
  37. Process process = builder.start();
  38. Scanner s = new Scanner(process.getInputStream());
  39. StringBuilder text = new StringBuilder();
  40. while (s.hasNextLine()) {
  41. text.append(s.nextLine());
  42. text.append("\n");
  43. }
  44. s.close();
  45. int result = process.waitFor();
  46. String[] lines = text.toString().split("\n");
  47. int idx = 0;
  48. for (int i = 0; i < lines.length; i++) {
  49. if ("======= 9th.sol:ERC721PresetMinterPauserAutoId =======".equals(lines[i])) {
  50. idx = i;
  51. break;
  52. }
  53. }
  54. System.out.println(lines[idx]);
  55. System.out.println(lines[idx + 2]);
  56. nftService.deployContract("nine_space_test" + System.currentTimeMillis(), lines[idx + 2]);
  57. }
  58. }