-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add @celo/celocli -- when doing transfers or exchanges ensure that all addresses complied with OFAC sanctions * add basic tests for transfers + compliance * add dynamic list checking. sadly means knew dep but its already a transitative dep so ok * fewer lines but same result, thanks nico * latest compliance package for good measure --------- Co-authored-by: Aaron <[email protected]>
- Loading branch information
Showing
16 changed files
with
317 additions
and
7 deletions.
There are no files selected for viewing
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,5 @@ | ||
--- | ||
'@celo/celocli': patch | ||
--- | ||
|
||
Require addresses the cli sends from or to not to be sanctioned |
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
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,85 @@ | ||
import { COMPLIANT_ERROR_RESPONSE, SANCTIONED_ADDRESSES } from '@celo/compliance' | ||
import { ContractKit, newKitFromWeb3 } from '@celo/contractkit' | ||
import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' | ||
import Web3 from 'web3' | ||
import { testLocally } from '../../test-utils/cliUtils' | ||
import TransferCelo from './celo' | ||
|
||
process.env.NO_SYNCCHECK = 'true' | ||
|
||
// Lots of commands, sometimes times out | ||
jest.setTimeout(15000) | ||
|
||
testWithGanache('transfer:celo cmd', (web3: Web3) => { | ||
let accounts: string[] = [] | ||
let kit: ContractKit | ||
|
||
beforeEach(async () => { | ||
kit = newKitFromWeb3(web3) | ||
accounts = await web3.eth.getAccounts() | ||
}) | ||
|
||
test('can transfer celo', async () => { | ||
const balanceBefore = await kit.getTotalBalance(accounts[0]) | ||
const receiverBalanceBefore = await kit.getTotalBalance(accounts[1]) | ||
const amountToTransfer = '500000000000000000000' | ||
// Send cUSD to RG contract | ||
await testLocally(TransferCelo, [ | ||
'--from', | ||
accounts[0], | ||
'--to', | ||
accounts[1], | ||
'--value', | ||
amountToTransfer, | ||
'--gasCurrency', | ||
'cusd', | ||
]) | ||
// RG cUSD balance should match the amount sent | ||
const receiverBalance = await kit.getTotalBalance(accounts[1]) | ||
expect(receiverBalance.CELO!.toFixed()).toEqual( | ||
receiverBalanceBefore.CELO!.plus(amountToTransfer).toFixed() | ||
) | ||
// Attempt to send cUSD back | ||
await testLocally(TransferCelo, [ | ||
'--from', | ||
accounts[1], | ||
'--to', | ||
accounts[0], | ||
'--value', | ||
amountToTransfer, | ||
'--gasCurrency', | ||
'cusd', | ||
]) | ||
const balanceAfter = await kit.getTotalBalance(accounts[0]) | ||
expect(balanceBefore.CELO).toEqual(balanceAfter.CELO) | ||
}) | ||
|
||
test('should fail if to address is sanctioned', async () => { | ||
const spy = jest.spyOn(console, 'log') | ||
await expect( | ||
testLocally(TransferCelo, [ | ||
'--from', | ||
accounts[1], | ||
'--to', | ||
SANCTIONED_ADDRESSES[0], | ||
'--value', | ||
'1', | ||
]) | ||
).rejects.toThrow() | ||
expect(spy).toHaveBeenCalledWith(expect.stringContaining(COMPLIANT_ERROR_RESPONSE)) | ||
}) | ||
test('should fail if from address is sanctioned', async () => { | ||
const spy = jest.spyOn(console, 'log') | ||
await expect( | ||
testLocally(TransferCelo, [ | ||
'--from', | ||
SANCTIONED_ADDRESSES[0], | ||
'--to', | ||
accounts[0], | ||
'--value', | ||
'1', | ||
]) | ||
).rejects.toThrow() | ||
expect(spy).toHaveBeenCalledWith(expect.stringContaining(COMPLIANT_ERROR_RESPONSE)) | ||
}) | ||
}) |
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,71 @@ | ||
import { COMPLIANT_ERROR_RESPONSE, SANCTIONED_ADDRESSES } from '@celo/compliance' | ||
import { ContractKit, newKitFromWeb3 } from '@celo/contractkit' | ||
import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' | ||
import Web3 from 'web3' | ||
import { testLocally } from '../../test-utils/cliUtils' | ||
import TransferCUSD from './dollars' | ||
|
||
process.env.NO_SYNCCHECK = 'true' | ||
|
||
// Lots of commands, sometimes times out | ||
jest.setTimeout(15000) | ||
|
||
testWithGanache('transfer:dollars cmd', (web3: Web3) => { | ||
let accounts: string[] = [] | ||
let kit: ContractKit | ||
|
||
beforeEach(async () => { | ||
kit = newKitFromWeb3(web3) | ||
accounts = await web3.eth.getAccounts() | ||
}) | ||
|
||
test('can transfer cusd', async () => { | ||
const balanceBefore = await kit.getTotalBalance(accounts[0]) | ||
const receiverBalanceBefore = await kit.getTotalBalance(accounts[1]) | ||
const amountToTransfer = '500000000000000000000' | ||
// Send cUSD to RG contract | ||
await testLocally(TransferCUSD, [ | ||
'--from', | ||
accounts[0], | ||
'--to', | ||
accounts[1], | ||
'--value', | ||
amountToTransfer, | ||
'--gasCurrency', | ||
'CELO', | ||
]) | ||
// RG cUSD balance should match the amount sent | ||
const receiverBalance = await kit.getTotalBalance(accounts[1]) | ||
expect(receiverBalance.cUSD!.toFixed()).toEqual( | ||
receiverBalanceBefore.cUSD!.plus(amountToTransfer).toFixed() | ||
) | ||
// Attempt to send cUSD back | ||
await testLocally(TransferCUSD, [ | ||
'--from', | ||
accounts[1], | ||
'--to', | ||
accounts[0], | ||
'--value', | ||
amountToTransfer, | ||
'--gasCurrency', | ||
'CELO', | ||
]) | ||
const balanceAfter = await kit.getTotalBalance(accounts[0]) | ||
expect(balanceBefore.cUSD).toEqual(balanceAfter.cUSD) | ||
}) | ||
|
||
test('should fail if to address is sanctioned', async () => { | ||
const spy = jest.spyOn(console, 'log') | ||
await expect( | ||
testLocally(TransferCUSD, [ | ||
'--from', | ||
accounts[1], | ||
'--to', | ||
SANCTIONED_ADDRESSES[0], | ||
'--value', | ||
'1', | ||
]) | ||
).rejects.toThrow() | ||
expect(spy).toHaveBeenCalledWith(expect.stringContaining(COMPLIANT_ERROR_RESPONSE)) | ||
}) | ||
}) |
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,71 @@ | ||
import { COMPLIANT_ERROR_RESPONSE, SANCTIONED_ADDRESSES } from '@celo/compliance' | ||
import { ContractKit, newKitFromWeb3 } from '@celo/contractkit' | ||
import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' | ||
import Web3 from 'web3' | ||
import { testLocally } from '../../test-utils/cliUtils' | ||
import TransferEURO from './euros' | ||
|
||
process.env.NO_SYNCCHECK = 'true' | ||
|
||
// Lots of commands, sometimes times out | ||
jest.setTimeout(15000) | ||
|
||
testWithGanache('transfer:euros cmd', (web3: Web3) => { | ||
let accounts: string[] = [] | ||
let kit: ContractKit | ||
|
||
beforeEach(async () => { | ||
kit = newKitFromWeb3(web3) | ||
accounts = await web3.eth.getAccounts() | ||
}) | ||
|
||
test('can transfer ceur', async () => { | ||
const balanceBefore = await kit.getTotalBalance(accounts[0]) | ||
const receiverBalanceBefore = await kit.getTotalBalance(accounts[1]) | ||
const amountToTransfer = '500000000000000000000' | ||
// Send cEUR to RG contract | ||
await testLocally(TransferEURO, [ | ||
'--from', | ||
accounts[0], | ||
'--to', | ||
accounts[1], | ||
'--value', | ||
amountToTransfer, | ||
'--gasCurrency', | ||
'CELO', | ||
]) | ||
// RG cEUR balance should match the amount sent | ||
const receiverBalance = await kit.getTotalBalance(accounts[1]) | ||
expect(receiverBalance.cEUR!.toFixed()).toEqual( | ||
receiverBalanceBefore.cEUR!.plus(amountToTransfer).toFixed() | ||
) | ||
// Attempt to send cEUR back | ||
await testLocally(TransferEURO, [ | ||
'--from', | ||
accounts[1], | ||
'--to', | ||
accounts[0], | ||
'--value', | ||
amountToTransfer, | ||
'--gasCurrency', | ||
'CELO', | ||
]) | ||
const balanceAfter = await kit.getTotalBalance(accounts[0]) | ||
expect(balanceBefore.cEUR).toEqual(balanceAfter.cEUR) | ||
}) | ||
|
||
test('should fail if to address is sanctioned', async () => { | ||
const spy = jest.spyOn(console, 'log') | ||
await expect( | ||
testLocally(TransferEURO, [ | ||
'--from', | ||
accounts[1], | ||
'--to', | ||
SANCTIONED_ADDRESSES[0], | ||
'--value', | ||
'1', | ||
]) | ||
).rejects.toThrow() | ||
expect(spy).toHaveBeenCalledWith(expect.stringContaining(COMPLIANT_ERROR_RESPONSE)) | ||
}) | ||
}) |
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
Oops, something went wrong.