-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #333 from massalabs/feat/asesrt-is-smart-contract
Add assertIsSmartContract function and tests
- Loading branch information
Showing
4 changed files
with
105 additions
and
15 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,44 @@ | ||
import { | ||
Address, | ||
addAddressToLedger, | ||
assertIsSmartContract, | ||
setBytecodeOf, | ||
} from '../..'; | ||
|
||
const validSCAddress = 'AS1uku77MYEHy3i12WeERtD2JQzeKePz5zmJjWCq6A8wWyZakccQ'; | ||
const invalidSCAddress = 'AS1uu77MYeERtD2JQzeKePz5zmJjWCq6A'; | ||
const userAddress = 'AU1UpieCqHKxzYYh47YbQEHdecMQJM5VsFMn7pS2tn37bxsfdxJ5'; | ||
const noByteAddress = 'AS1uku77MYEHy3i12WeERtD2JQzeKePz5zmJjWCq6A8wWyZakccQ'; | ||
|
||
describe('assertAddressIsSmartContract', (): void => { | ||
throws('for an invalid address', (): void => { | ||
// The address is invalid but the mock ledger doesn't know that | ||
// so we can still set the bytecode and we are sure it fail for the right reason | ||
addAddressToLedger(invalidSCAddress); | ||
setBytecodeOf(new Address(validSCAddress), [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]); | ||
|
||
assertIsSmartContract(invalidSCAddress); | ||
}); | ||
|
||
throws('for a user address', (): void => { | ||
addAddressToLedger(userAddress); | ||
assertIsSmartContract(userAddress); | ||
}); | ||
|
||
throws('for a sc address with no bytecode', (): void => { | ||
addAddressToLedger(noByteAddress); | ||
assertIsSmartContract(noByteAddress); | ||
}); | ||
|
||
throws('for a sc address with bytecode empty', (): void => { | ||
addAddressToLedger(validSCAddress); | ||
setBytecodeOf(new Address(validSCAddress), []); | ||
assertIsSmartContract(validSCAddress); | ||
}); | ||
|
||
it('should not throw for a valid smart contract address', (): void => { | ||
addAddressToLedger(validSCAddress); | ||
setBytecodeOf(new Address(validSCAddress), [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]); | ||
assertIsSmartContract(validSCAddress); | ||
}); | ||
}); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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