Skip to content
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

Erc20 transfer #660

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/contracts-wrappers/token.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Args, U256 } from '../basicElements'
import { Operation } from '../operation'
import { ReadSCOptions, SmartContract } from '../smartContracts'

export class MRC20 extends SmartContract {
Expand All @@ -10,5 +11,17 @@
)
return U256.fromBytes(res.value)
}

async transfer(

Check warning on line 15 in src/contracts-wrappers/token.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
to: string,
amount: bigint,
options?: ReadSCOptions
): Promise<Operation> {
return this.call(
'transfer',
new Args().addString(to).addU256(amount),
options
)

Check warning on line 24 in src/contracts-wrappers/token.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}
// TODO: Implement the rest of the functions
}
13 changes: 11 additions & 2 deletions test/integration/MRC20.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@ describe('Token wrapper tests', () => {
usdcContract = new MRC20(provider, USDC)
})

test('balanceOf', async () => {
test('transfer', async () => {
const amount = 1_000n
const balance = await usdcContract.balanceOf(provider.address)
expect(balance).toBeGreaterThan(0n)

const operation = await usdcContract.transfer(
'AU1wN8rn4SkwYSTDF3dHFY4U28KtsqKL1NnEjDZhHnHEy6cEQm53',
amount
)
await operation.waitSpeculativeExecution()

const newBalance = await usdcContract.balanceOf(provider.address)
expect(newBalance).toBe(balance - amount)
})
})
2 changes: 2 additions & 0 deletions test/integration/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Web3Provider } from '../../src/provider'
export let account: Account
export let provider: Web3Provider

jest.setTimeout(120_000)

beforeAll(async () => {
account = await Account.fromEnv()
provider = Web3Provider.buildnet(account)
Expand Down
Loading