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. // TODO: Re-enable this test when ephemeral-validator is properly installed on the CI.
  25. // await Profiler.Run("ApplySimpleMovementSystemOnAccelerator 10", async () => {
  26. // await ApplySimpleMovementSystemOnAccelerator(framework);
  27. // });
  28. }
  29. public static async Task AddAccelerationEntity(Framework framework) {
  30. var addEntity = await Bolt.World.AddEntity(framework.Client, framework.WorldPda, framework.Wallet.Account.PublicKey, Commitment.Processed);
  31. framework.AccelerationEntityPda = addEntity.Pda;
  32. await framework.SendAndConfirmInstruction(addEntity.Instruction);
  33. }
  34. public static async Task InitializePositionComponentOnAccelerationEntity(Framework framework) {
  35. var initializeComponent = await Bolt.World.InitializeComponent(framework.Wallet.Account.PublicKey, framework.AccelerationEntityPda, framework.ExampleComponentPosition);
  36. framework.AccelerationComponentPositionPda = initializeComponent.Pda;
  37. await framework.SendAndConfirmInstruction(initializeComponent.Instruction);
  38. }
  39. public static async Task DelegateComponent(Framework framework) {
  40. var delegateComponent = await Bolt.World.DelegateComponent(framework.Wallet.Account.PublicKey, framework.AccelerationEntityPda, framework.ExampleComponentPosition);
  41. await framework.SendAndConfirmInstruction(delegateComponent.Instruction);
  42. }
  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. }