-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added transfer ticket to the wallet API and updated integration tests #3003
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing ticketsSendTz originated here the 2nd time made me want to originate it at
integration-tests/originate-known-contracts.ts
as knownTicketContract. Andintegration-tests/__tests__/rpc/nodes.spec.ts
can benefit from this too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's not a bad idea, we can make a ticket for that.