Skip to content

Commit

Permalink
feat: Token2022ProgramTests
Browse files Browse the repository at this point in the history
  • Loading branch information
bigearsenal committed Jan 4, 2024
1 parent 832c0ad commit 987a380
Showing 1 changed file with 211 additions and 0 deletions.
211 changes: 211 additions & 0 deletions Tests/SolanaSwiftUnitTests/Programs/Token2022ProgramTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
import SolanaSwift
import XCTest

class Token2022ProgramTests: XCTestCase {
func testInitializeMintInstruction() throws {
let instruction = Token2022Program.initializeMintInstruction(
mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
decimals: 6,
authority: "3h1zGmCwsRJnVk5BuRNMLsPaQu1y2aqXqXDWYCgrp5UG",
freezeAuthority: nil
)

XCTAssertEqual(instruction.keys.count, 2)
XCTAssertEqual(
instruction.keys[0],
.writable(publicKey: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", isSigner: false)
)
XCTAssertEqual(
instruction.keys[1],
.readonly(publicKey: "SysvarRent111111111111111111111111111111111", isSigner: false)
)
XCTAssertEqual(instruction.programId, Token2022Program.id)
XCTAssertEqual(Base58.encode(instruction.data), "195AHs4ykNczn89ynGjJ5v7rSfaK9giG1eL2bNrmUqn1oNw")
}

func testInitializeAccountInstruction() throws {
let instruction = Token2022Program.initializeAccountInstruction(
account: "GrDMoeqMLFjeXQ24H56S1RLgT4R76jsuWCd6SvXyGPQ5",
mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
owner: "3h1zGmCwsRJnVk5BuRNMLsPaQu1y2aqXqXDWYCgrp5UG"
)

XCTAssertEqual(instruction.keys.count, 4)
XCTAssertEqual(
instruction.keys[0],
.writable(publicKey: "GrDMoeqMLFjeXQ24H56S1RLgT4R76jsuWCd6SvXyGPQ5", isSigner: false)
)
XCTAssertEqual(
instruction.keys[1],
.readonly(publicKey: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", isSigner: false)
)
XCTAssertEqual(
instruction.keys[2],
.readonly(publicKey: "3h1zGmCwsRJnVk5BuRNMLsPaQu1y2aqXqXDWYCgrp5UG", isSigner: false)
)
XCTAssertEqual(
instruction.keys[3],
.readonly(publicKey: "SysvarRent111111111111111111111111111111111", isSigner: false)
)
XCTAssertEqual(instruction.programId, Token2022Program.id)
XCTAssertEqual(Base58.encode(instruction.data), "2")
}

func testTransferInstruction() throws {
let instruction = Token2022Program.transferInstruction(
source: "GrDMoeqMLFjeXQ24H56S1RLgT4R76jsuWCd6SvXyGPQ5",
destination: "3uetDDizgTtadDHZzyy9BqxrjQcozMEkxzbKhfZF4tG3",
owner: "3h1zGmCwsRJnVk5BuRNMLsPaQu1y2aqXqXDWYCgrp5UG",
amount: 100
)

XCTAssertEqual(instruction.keys.count, 3)
XCTAssertEqual(
instruction.keys[0],
.writable(publicKey: "GrDMoeqMLFjeXQ24H56S1RLgT4R76jsuWCd6SvXyGPQ5", isSigner: false)
)
XCTAssertEqual(
instruction.keys[1],
.writable(publicKey: "3uetDDizgTtadDHZzyy9BqxrjQcozMEkxzbKhfZF4tG3", isSigner: false)
)
XCTAssertEqual(
instruction.keys[2],
.writable(publicKey: "3h1zGmCwsRJnVk5BuRNMLsPaQu1y2aqXqXDWYCgrp5UG", isSigner: true)
)
XCTAssertEqual(instruction.programId, Token2022Program.id)
XCTAssertEqual("3WBgs5fm8oDy", Base58.encode(instruction.data))
}

func testTransferCheckedInstruction() throws {
let instruction = Token2022Program.transferCheckedInstruction(
source: "GrDMoeqMLFjeXQ24H56S1RLgT4R76jsuWCd6SvXyGPQ5",
mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
destination: "3uetDDizgTtadDHZzyy9BqxrjQcozMEkxzbKhfZF4tG3",
owner: "3h1zGmCwsRJnVk5BuRNMLsPaQu1y2aqXqXDWYCgrp5UG",
multiSigners: [],
amount: 100,
decimals: 6
)

XCTAssertEqual(instruction.keys.count, 4)
XCTAssertEqual(
instruction.keys[0],
.writable(publicKey: "GrDMoeqMLFjeXQ24H56S1RLgT4R76jsuWCd6SvXyGPQ5", isSigner: false)
)
XCTAssertEqual(
instruction.keys[1],
.readonly(publicKey: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", isSigner: false)
)
XCTAssertEqual(
instruction.keys[2],
.writable(publicKey: "3uetDDizgTtadDHZzyy9BqxrjQcozMEkxzbKhfZF4tG3", isSigner: false)
)
XCTAssertEqual(
instruction.keys[3],
.readonly(publicKey: "3h1zGmCwsRJnVk5BuRNMLsPaQu1y2aqXqXDWYCgrp5UG", isSigner: true)
)
XCTAssertEqual(instruction.programId, Token2022Program.id)
XCTAssertEqual("hNmtbNYibdzwf", Base58.encode(instruction.data))
}

func testBurnCheckedInstruction() throws {
let instruction = Token2022Program.burnCheckedInstruction(
mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
account: "GrDMoeqMLFjeXQ24H56S1RLgT4R76jsuWCd6SvXyGPQ5",
owner: "3h1zGmCwsRJnVk5BuRNMLsPaQu1y2aqXqXDWYCgrp5UG",
amount: 100,
decimals: 6
)

XCTAssertEqual(instruction.keys.count, 3)
XCTAssertEqual(
instruction.keys[0],
.writable(publicKey: "GrDMoeqMLFjeXQ24H56S1RLgT4R76jsuWCd6SvXyGPQ5", isSigner: false)
)
XCTAssertEqual(
instruction.keys[1],
.writable(publicKey: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", isSigner: false)
)
XCTAssertEqual(
instruction.keys[2],
.readonly(publicKey: "3h1zGmCwsRJnVk5BuRNMLsPaQu1y2aqXqXDWYCgrp5UG", isSigner: true)
)
XCTAssertEqual(instruction.programId, Token2022Program.id)
XCTAssertEqual("s9m8UUrvs3fBT", Base58.encode(instruction.data))
}

func testApproveInstruction() throws {
let instruction = Token2022Program.approveInstruction(
account: "GrDMoeqMLFjeXQ24H56S1RLgT4R76jsuWCd6SvXyGPQ5",
delegate: "QqCCvshxtqMAL2CVALqiJB7uEeE5mjSPsseQdDzsRUo",
owner: "3h1zGmCwsRJnVk5BuRNMLsPaQu1y2aqXqXDWYCgrp5UG",
multiSigners: [],
amount: 1000
)

XCTAssertEqual(instruction.keys.count, 3)
XCTAssertEqual(
instruction.keys[0],
.writable(publicKey: "GrDMoeqMLFjeXQ24H56S1RLgT4R76jsuWCd6SvXyGPQ5", isSigner: false)
)
XCTAssertEqual(
instruction.keys[1],
.readonly(publicKey: "QqCCvshxtqMAL2CVALqiJB7uEeE5mjSPsseQdDzsRUo", isSigner: false)
)
XCTAssertEqual(
instruction.keys[2],
.readonly(publicKey: "3h1zGmCwsRJnVk5BuRNMLsPaQu1y2aqXqXDWYCgrp5UG", isSigner: true)
)
XCTAssertEqual(instruction.programId, Token2022Program.id)
XCTAssertEqual("4d5tSvUuzUVM", Base58.encode(instruction.data))
}

func testMintToInstruction() throws {
let instruction = Token2022Program.mintToInstruction(
mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
destination: "3uetDDizgTtadDHZzyy9BqxrjQcozMEkxzbKhfZF4tG3",
authority: "3h1zGmCwsRJnVk5BuRNMLsPaQu1y2aqXqXDWYCgrp5UG",
amount: 1_000_000_000
)

XCTAssertEqual(instruction.keys.count, 3)
XCTAssertEqual(
instruction.keys[0],
.writable(publicKey: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", isSigner: false)
)
XCTAssertEqual(
instruction.keys[1],
.writable(publicKey: "3uetDDizgTtadDHZzyy9BqxrjQcozMEkxzbKhfZF4tG3", isSigner: false)
)
XCTAssertEqual(
instruction.keys[2],
.writable(publicKey: "3h1zGmCwsRJnVk5BuRNMLsPaQu1y2aqXqXDWYCgrp5UG", isSigner: true)
)
XCTAssertEqual(instruction.programId, Token2022Program.id)
XCTAssertEqual("6AsKhot84V8s", Base58.encode(instruction.data))
}

func testCloseAccountInstruction() throws {
let instruction = Token2022Program.closeAccountInstruction(
account: "3uetDDizgTtadDHZzyy9BqxrjQcozMEkxzbKhfZF4tG3",
destination: "QqCCvshxtqMAL2CVALqiJB7uEeE5mjSPsseQdDzsRUo",
owner: "3h1zGmCwsRJnVk5BuRNMLsPaQu1y2aqXqXDWYCgrp5UG"
)

XCTAssertEqual(instruction.keys.count, 3)
XCTAssertEqual(
instruction.keys[0],
.writable(publicKey: "3uetDDizgTtadDHZzyy9BqxrjQcozMEkxzbKhfZF4tG3", isSigner: false)
)
XCTAssertEqual(
instruction.keys[1],
.writable(publicKey: "QqCCvshxtqMAL2CVALqiJB7uEeE5mjSPsseQdDzsRUo", isSigner: false)
)
XCTAssertEqual(
instruction.keys[2],
.readonly(publicKey: "3h1zGmCwsRJnVk5BuRNMLsPaQu1y2aqXqXDWYCgrp5UG", isSigner: false)
)
XCTAssertEqual(instruction.programId, Token2022Program.id)
XCTAssertEqual("A", Base58.encode(instruction.data))
}
}

0 comments on commit 987a380

Please sign in to comment.