-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added transfer ticket to the wallet API and updated integration tests (…
…#3003) * added transfer ticket to the wallet API and updated integration tests * used methodsObject() instead of the deprecated methods()
- Loading branch information
Showing
8 changed files
with
211 additions
and
1 deletion.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
integration-tests/__tests__/wallet/transfer-ticket-operation.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { CONFIGS } from '../../config'; | ||
import { DefaultContractType, TezosToolkit } from '@taquito/taquito'; | ||
import { ticketsSendTz } from '../../data/code_with_ticket_transfer'; | ||
import { RpcClient, TicketTokenParams } from '@taquito/rpc'; | ||
|
||
CONFIGS().forEach(({ lib, rpc, setup, createAddress }) => { | ||
const Tezos = lib; | ||
const client = new RpcClient(rpc); | ||
|
||
let ticketSendContract: DefaultContractType; | ||
let recipient: TezosToolkit; | ||
let sender: TezosToolkit; | ||
let recipientPkh: string; | ||
let senderPkh: string | ||
let ticketToken: TicketTokenParams; | ||
|
||
describe(`Transfer tickets between implicit accounts using: ${rpc}`, () => { | ||
|
||
beforeAll(async () => { | ||
await setup(true); | ||
try { | ||
recipient = await createAddress(); | ||
sender = await createAddress(); | ||
|
||
recipientPkh = await recipient.signer.publicKeyHash(); | ||
senderPkh = await sender.wallet.pkh(); | ||
|
||
const fundSender = await Tezos.contract.transfer({ to: senderPkh, amount: 5 }); | ||
await fundSender.confirmation(); | ||
|
||
const ticketSendOrigination = await Tezos.contract.originate({ code: ticketsSendTz, storage: null }); | ||
await ticketSendOrigination.confirmation(); | ||
|
||
ticketSendContract = await ticketSendOrigination.contract(); | ||
ticketToken = { ticketer: ticketSendContract.address, content_type: { prim: 'string' }, content: { string: 'Ticket' } }; | ||
|
||
// Send 3 tickets from the originated contract to sender | ||
const sendTickets = await ticketSendContract.methodsObject.default([senderPkh, '3']).send() | ||
await sendTickets.confirmation(); | ||
|
||
} catch (error) { | ||
console.log(error); | ||
} | ||
}); | ||
|
||
it('should transfer 1 ticket from an implicit account to another implicit account using a Wallet', async () => { | ||
// Check balances before transferring tickets | ||
const balanceBefore = await client.getTicketBalance(recipientPkh, ticketToken); | ||
expect(balanceBefore).toEqual('0'); | ||
|
||
const senderBalanceBefore = await client.getTicketBalance(senderPkh, ticketToken); | ||
expect(senderBalanceBefore).toEqual('3'); | ||
|
||
// Transfer 1 ticket from sender to recipient | ||
const transferTicketOp = await sender.wallet.transferTicket({ | ||
ticketContents: { string: "Ticket" }, | ||
ticketTy: { prim: "string" }, | ||
ticketTicketer: ticketSendContract.address, | ||
ticketAmount: 1, | ||
destination: recipientPkh, | ||
entrypoint: 'default', | ||
}).send(); | ||
|
||
await transferTicketOp.confirmation(); | ||
|
||
expect(await transferTicketOp.status()).toEqual('applied'); | ||
|
||
// Check balances after transferring tickets | ||
const balanceAfter = await client.getTicketBalance(recipientPkh, ticketToken); | ||
expect(balanceAfter).toEqual('1'); | ||
|
||
const senderBalanceAfter = await client.getTicketBalance(senderPkh, ticketToken); | ||
expect(senderBalanceAfter).toEqual('2'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { WalletOperation, OperationStatus } from './operation'; | ||
import { Context } from '../context'; | ||
import { Observable } from 'rxjs'; | ||
import { | ||
BlockResponse, | ||
OpKind, | ||
OperationContentsAndResultReveal, | ||
OperationContentsAndResultTransferTicket, | ||
} from '@taquito/rpc'; | ||
import { ObservableError } from './errors'; | ||
|
||
export class TransferTicketWalletOperation extends WalletOperation { | ||
constructor( | ||
public readonly opHash: string, | ||
protected readonly context: Context, | ||
newHead$: Observable<BlockResponse> | ||
) { | ||
super(opHash, context, newHead$); | ||
} | ||
|
||
public async revealOperation() { | ||
const operationResult = await this.operationResults(); | ||
if (!operationResult) { | ||
throw new ObservableError('operationResult returned undefined'); | ||
} | ||
|
||
return operationResult.find((x) => x.kind === OpKind.REVEAL) as | ||
| OperationContentsAndResultReveal | ||
| undefined; | ||
} | ||
|
||
public async transferTicketOperation() { | ||
const operationResult = await this.operationResults(); | ||
if (!operationResult) { | ||
throw new ObservableError('operationResult returned undefined'); | ||
} | ||
return operationResult.find((x) => x.kind === OpKind.TRANSFER_TICKET) as | ||
| OperationContentsAndResultTransferTicket | ||
| undefined; | ||
} | ||
|
||
public async status(): Promise<OperationStatus> { | ||
if (!this._included) { | ||
return 'pending'; | ||
} | ||
|
||
const op = await this.transferTicketOperation(); | ||
if (!op) { | ||
return 'unknown'; | ||
} | ||
|
||
return op.metadata.operation_result.status; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters