AccelerationTest.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Solana.Unity.Bolt.Test;
  2. using Solana.Unity.Rpc.Models;
  3. using Solana.Unity.Wallet;
  4. using Solana.Unity.Bolt;
  5. using Solana.Unity.Rpc;
  6. using System;
  7. using System.Threading.Tasks;
  8. using Solana.Unity.Wallet.Bip39;
  9. using World.Program;
  10. using System.Diagnostics;
  11. using Solana.Unity.Rpc.Types;
  12. namespace AccelerationTest {
  13. public class Test {
  14. public static async Task Run(Framework framework) {
  15. await Profiler.Run("AddAccelerationEntity", async () => {
  16. await AddAccelerationEntity(framework);
  17. });
  18. await Profiler.Run("InitializePositionComponentOnAccelerationEntity", async () => {
  19. await InitializePositionComponentOnAccelerationEntity(framework);
  20. });
  21. await Profiler.Run("DelegateComponent", async () => {
  22. await DelegateComponent(framework);
  23. });
  24. await Profiler.Run("ApplySimpleMovementSystemOnAccelerator 10", async () => {
  25. await ApplySimpleMovementSystemOnAccelerator(framework);
  26. });
  27. }
  28. public static async Task AddAccelerationEntity(Framework framework) {
  29. var addEntity = await Bolt.World.AddEntity(framework.Client, framework.WorldPda, framework.Wallet.Account.PublicKey, Commitment.Processed);
  30. framework.AccelerationEntityPda = addEntity.Pda;
  31. await framework.SendAndConfirmInstruction(addEntity.Instruction);
  32. }
  33. public static async Task InitializePositionComponentOnAccelerationEntity(Framework framework) {
  34. var initializeComponent = await Bolt.World.InitializeComponent(framework.Wallet.Account.PublicKey, framework.AccelerationEntityPda, framework.ExampleComponentPosition);
  35. framework.AccelerationComponentPositionPda = initializeComponent.Pda;
  36. await framework.SendAndConfirmInstruction(initializeComponent.Instruction);
  37. }
  38. public static async Task DelegateComponent(Framework framework) {
  39. var delegateComponent = await Bolt.World.DelegateComponent(framework.Wallet.Account.PublicKey, framework.AccelerationEntityPda, framework.ExampleComponentPosition);
  40. await framework.SendAndConfirmInstruction(delegateComponent.Instruction);
  41. }
  42. // TODO: Re-enable this test when ephemeral-validator is properly installed on the CI.
  43. // public static async Task ApplySimpleMovementSystemOnAccelerator(Framework framework) {
  44. // for (int i = 0; i < 10; i++) {
  45. // var apply = new ApplyAccounts() {
  46. // Authority = framework.Wallet.Account.PublicKey,
  47. // BoltSystem = framework.SystemSimpleMovement,
  48. // World = framework.WorldPda,
  49. // };
  50. // var instruction = WorldProgram.Apply(apply, Bolt.World.SerializeArgs(new { direction = "Up" }));
  51. // instruction.Keys.Add(AccountMeta.ReadOnly(framework.ExampleComponentPosition, false));
  52. // instruction.Keys.Add(AccountMeta.Writable(framework.AccelerationComponentPositionPda, false));
  53. // await framework.SendAndConfirmInstruction(framework.AcceleratorClient, instruction);
  54. // await Task.Delay(50);
  55. // }
  56. // }
  57. }
  58. }